Practical Date/Time examples with PHP and MySQL - Dates with MySQL (Page 4 of 6 )
MySQL has several great date and time functions that are very useful when you are working with dates. These functions are worth another article which I’ll be writing after this one.
Meanwhile I’ll show the ones that I think are the more useful and interesting.
Also, forcing MySQL to do the date operations by itself saves a lot of time, a lot of code and increases the performance of your application.
Personally, every time that I need to do some date calculations involving dates contained in a database I take a look at MySQL documentation to see which function can help me and let it do the job for me.
In all the following examples the dates can be taken from the database itself, your code or user input.
Anyway, if you are working with databases it’s obvious that at least one of the dates came from there.
Take care when using these functions as most of them work only on MySQL 3.22 and later. If you have doubts refer to the documentation.
The UNIX timestamp revisited
Programmers seem to like the UNIX timestamp very much because you can see it anywhere you go. In the case of MySQL you can use it like this: