PDA

View Full Version : MySQL date format


Capt C Ray
05-05-2013, 11:47 AM
I want to run a query to identify all members that have visited my site in the last 2 years. But when I look at the date, it makes no sense to me. MySQL client version is 5.5.23. The date fields are defined as int(11), which I guess is normal.

What format of a date do I need to use in my query?

Thanks.

Ray

kh99
05-05-2013, 11:55 AM
The date is stored as a unix timestamp, which is seconds since Jan 1 1970. You can use the mySQL functions UNIX_TIMESTAMP() (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp) or FROM_UNIXTIME() (http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_from-unixtime) in your query to compare the field to a date string.

Capt C Ray
05-06-2013, 10:17 AM
I will assume the date format is mmddyyyy.
Thanks.

kh99
05-06-2013, 12:40 PM
I think there's a number of different date/time string formats that UNIXTIME_TIMESTAMP() is able to interpret: http://dev.mysql.com/doc/refman/5.0/en/datetime.html