hm9
March 16, 2011, 1:28pm
1
Hi,
I have two variables that store two dates in the format of yyyy-mm-dd.
I need to calculate the duration or difference between the two dates and store it in another variable, so I am using this format to store both dates in PHP
$DeparturedDate = “$year-$month-$day”
$ReturnDate = “$year-$month-$day”
and need something like this:
$Duration = ReturnDate - $DeparturedDate
Any ideas how to achieve this?
Thanks in advance
smftre
March 16, 2011, 3:49pm
2
$duration = strtotime($date1) - strtotime($date2);
hm9
March 16, 2011, 9:13pm
3
Thanks, but it returns a parse error:
Parse error: syntax error, unexpected T_VARIABLE in
Cups
March 17, 2011, 1:21am
4
I find it utterly fab that your reported parse error contains a truncated parse error!
What was the full message?
hm9
March 17, 2011, 9:32am
5
Cups: THAT was the error message!!!
Its sorted now, but the calculation always return 0.
not sure what it is?
For PHP 5.3 you could be using: PHP: DateTime::diff - Manual