I am wanting to find out the time difference in minutes between two dates which is in the format d-m-Y H:i (14-04-2009 12:15) using php?
+5
A:
Parse the times into timestamps using strtotime() and then simply subtract one from the other.
After that you can get the number of minutes, days and so on by using math functions.
For example:
// $date1 and $date2 are given
// the difference is in seconds
$difference = strtotime($date1) - strtotime($date2);
// getting the difference in minutes
$difference_in_minutes = $difference / 60;
More informations about strtotime(): http://de.php.net/manual/de/function.strtotime.php (german documentation)
brainfck
2009-11-20 13:57:43
PHP may assume your date is in m-d-Y format when the numbers for month and day make the format ambiguous (the example you give is unambiguous, as there are not 14 months). You may need to parse and swap the day and month.
Lucas Oman
2009-11-20 14:08:57
Of course, I didn't recognize that the given date is not in standard US-english format.
brainfck
2009-11-20 14:25:28
Exactly. strtotime might give you unexpected results since the date format you're using is unusual.
Salman A
2009-11-20 14:26:51
It is the date format used in GB.
Salman A
2009-11-20 14:27:34