MySQL Date Formats

Much like PHP, MySQL 5 uses a form of timestamp, but in its native form, it is not compatible with the PHP timestamp. MySQL has three time/date field types: DATE (a date), TIME (a time), and DATETIME (a date and a time). MySQL also has a special date field type called TIMESTAMP, which works like DATETIME but automatically updates to the current timestamp with every insert and update and has a different internal storage mechanism.

There are numerical ways of representing data in your queries for these types, but it's much easier to use a string in your SQL. For example, you can use 2008-09-26 as a date, 13:23:56 as a time, and 2008-09-26 13:23:56 as a date and time. To convert a PHP timestamp in $timestamp into a form suitable ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.