I want to store the date and time that a user performs an action on my website into a MySQL database. I'd like to be able to do the following with ease:
- Store the date and time as one field in the database
- Use a built in PHP or MySQL function to generate the date-time of the action
- Store the date-time based on my server's time, and not worry about user timezones.
Order By
the date-time field when I query MySQL- Later, display the date-time in many different formats using built in PHP methods
Here are my questions:
- What data type should I use in MySQL ( eg.
timestamp
,datetime
... )? - What method should I use to generate the date-time ( eg. MySQL's
now()
, PHP'sdate()
... )? - What PHP method should I later use to format the date-time in various pretty ways ( eg. 23/4/2012, 5pm on Monday, July 2012 ... )?