Page 1 of 1

Difference between 2 timestamps always a day extra

Posted: Sat Apr 09, 2005 2:37 am
by anjanesh
I want to find the number of days in-between two timestamps and date() is always return a day extra.

Code: Select all

echo strtotime("2005-01-04").'<br>';
echo strtotime("2005-01-04").'<br>';
echo date("d",strtotime("2005-01-04")-strtotime("2005-01-04")).'<br>';
This should return 0 days but returns 1.
How is this possible ?
Thanks

Posted: Sat Apr 09, 2005 2:57 am
by timvw
actually, it is date("d", 0) that returns 01

Code: Select all

echo strtotime("2005-01-04")-strtotime("2005-01-04");
echo "<br>";
echo date("d", 0);
outputs:

0
01

Posted: Thu Apr 14, 2005 4:53 pm
by feyd
short explanation of why it happens: 'd' is the current day of the timestamp provided. A timestamp of zero is January 1st, 1970. If you google the "unix epoch" you should find further explanations, although they may not be satisfying.