Php dating

A concrete example where we use this feature (inspired from php.net)No problem for mktime, it will find calculate what date in the year it is!

With these function you should now be able to build all the basic functions you need for dates.

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 see some examples: The second argument of strtotime is a timestamp, and its default value is the actual timestamp (time()).

So echo strtotime(' 4 days') is relative to the current time.

To compare dates, it's now just a detail: Be aware not to prefix the values with '0' (like '02'), PHP will treat it as an octal value (default PHP behaviour)!

These date inputs are used to form a database query to read rows within two dates by the use of BETWEEN clause.

Of course you can also give strtotime your mysql date!

(Note you can also use the mysql function UNIX_TIMESTAMP, which use a bit more ressources).

The function will correct the values for you: if you give it '', you will get the timestamp of the date '04-2-2008'!

That's very interesting for us, because we don't have to care anymore about being in the range for the day, the month, ...

Leave a Reply