Can anybody give me an idea why I am getting different results when comparing what are the same date values?
I do this select in my PHP page from a mySQL database:
select DATE_FORMAT(min(date_now), '%l,%i,%s,%m,%d,%Y'), DATE_FORMAT(max(date_now), '%l,%i,%s,%m,%d,%Y') from MYTABLE where name_id=2
Which gives me:
10,23,15,05,30,2008 ($startTime)
12,15,13,05,30,2008 ($EndTime)
I assign the above to two variables then use mktime to get the time difference:
$dateDiff = mktime($EndTime) - mktime($StartTime)
The result from this is wrong, the result returned is:
Difference in seconds: 7200
If I manually assign the variables, which is exactly what is contained in the variables I get the correct result:
$dateDiff = mktime(12,15,13,05,30,2008) - mktime(10,23,15,05,30,2008);
Difference in seconds: 6718
I’ve worked out that when I use mktime with a variable the results are slightly different:
$dateDiff1 = mktime($EndTime) ;
$dateDiff2 = mktime($StartTime);
Result:
1212148650
1212141450
And when I assign the dates manually:
$dateDiff1 = mktime(12,15,13,05,30,2008);
$dateDiff2 = mktime(10,23,15,05,30,2008);
Result:
1212146113
1212139395
Why is this happening and how can I make it work correctly?
Thanks