I'm trying to figure out how to compare against date()
. I'm following along in a tutorial about how to use this function to compare the current time against the time a cache file was last modified. In the tutorial, the author uses "10800" as 3 hours and the code looks something like:
(filemtime($cache) < (time()-10800))
I have no problem understanding how this comparison works but I just don't get how the the expression of time, "10800", is formatted.
Just for the record I spent a solid 15 minutes looking for an answer so I'm not just being ignorant of Google haha.
Thanks!
It's in seconds,
3 hours = 3 * 60 * 60 = 10800 seconds
As time function returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). You neeed to subtract 10800
from it to get timestamp of time before 3 hours
.
10800 is in seconds..
all unix timestamps are measured in seconds since the epoch... 1 being the first second of 1970.
This explains why when you have a bad strtotime value and you are interpreting it with date i.e.
date(strtotime("last tomorrowday"));
it ends up showing you 1969-12-31 ... strtotime is returning 0 and if 1 is the first second of 1970 then 0 will be interpreted as the last second of 1969