txt3rob — 2013-12-05T06:00:22-05:00 — #1
I have the following
$due = substr($result['Due'], 0, 5);
$now = date('h:i');
due time is 12hr clock so 01:15
how can i get to show how many mins between the two values
guido2004 — 2013-12-05T06:55:25-05:00 — #2
If it's a 12hr clock, how do you know if it's AM or PM ?
And what does $result['Due'] contain, a complete timestamp?
droopsnoot — 2013-12-05T06:55:44-05:00 — #3
On a very basic level
$d = (strtotime($now) - strtotime($due))/60;
but I haven't tested whether that will work if $now is earlier than $due, and you'd want to check validity and so on. Though abs() would probably cover the first point. Also a quick google suggests you should look at the DateTime class to do stuff like this now.
ETA: also what Guido said, result is probably meaningless if you don't know whether due time is am or pm. If you're truncating the due time because it also contains 'am' or 'pm', I get the impression strtotime() will handle that.
txt3rob — 2013-12-05T06:59:58-05:00 — #4
due contains 12hr time with seconds but i have to strip the seconds off.
i now see why you ask about am or pm but none of the times have am or pm
txt3rob — 2013-12-05T07:02:32-05:00 — #5
that actually works but it does show -5 tho
droopsnoot — 2013-12-05T13:44:40-05:00 — #6
Well, that must mean that the due time is later than the current time when you ran it. Change it to
$d = abs((strtotime($now)-strtotime($due))/60);
But it won't make any sense if you don't know whether $due means 01:15 as 1:15am or 1:15pm.