Hallo, I want to find the difference between today and another date,
convert todays date into unix time format here
<?php
echo '1st one'.strtotime(date("d.m.Y")).'<br>';
echo '2nd one'.strtotime(date("m.d.Y")).'<br>';
?>
The first echo is producing some value, but not the second one. What is the bug in it…please help..
strtotimemakes assumptions based on the date format you give it. For instanceNote that when given an invalid date, strtotime defaults to the timestamp for 1969-12-31 19:00:00, so when you end up with an unexpected date in 1969, you know you’re working with an invalid date.
Because
strtotimeis looking for day.month.year when you use.as the delimiter, so it sees “9.27.2010” as the 9th day of the 27th month, which obviously doesn’t exist.However, if you change it to use
/as the delimiter:In this case,
strtotimeexpects dates in month/day/year format.If you want to be safe, Y-m-d is generally a good format to use.