The Tricky.net

PHP
Compare dates with PHP

I read a lot of people having trouble while comparing dates with php, trying to guess with some substring functions if date A is before or after date B. I would like to introduce some very convenient functions which simplify greatly your life.

Let's begin with the definition of a timestamp : it's simply the number of seconds elapsed since the 1st january 1970. Yes, the number of seconds, it seems maybe a bit odd, but you discover then that these timestamps are very practical to manipulate: comparing dates, adding some days to a date, differences between dates, all these can be easily done with timestamps.

Obviously, you think: and dates before 1970??? Depends of the platform on which runs PHP: on Windows, you cannot have negative timestamps, and it's the same problem with some linux distribution. You'll have to try to know, but if you get false, -1 or "1 jan 1970" as result of the function returning a timestamp with a correct date given, it's bad news. If it's ok, know you can normally handle dates between 13 december 1901 and 19 january 2038.

Read more...
 
More Articles...
<< Start < Prev 1 2 3 4 5 6 7 Next > End >>

Page 6 of 7