We could use a normal character field to store date or time information, but DATE, DATETIME, and TIMESTAMP are more efficient for this purpose. MySQL checks the contents to ensure valid date and time information, and offers special functions to work on these fields.
As an added benefit, phpMyAdmin offers a calendar popup for easy data entry.
We will start by adding a DATE field, date_published, to our book table. If we go into Insert mode, we should now see the new field where we could type a date. A Calendar icon is also available:
This icon brings a popup window, synchronized to this DATE field: if there is already a value in the field, the popup displays accordingly. In our case, there is no value in the field, so the calendar shows the current date:
Small symbols on each side of the month and year headers permit easy scrolling through months and years, and a simple click on the date we want transports it to our date_published field.
For...