Jump to content

DATETIME type in MySQL database


boylesg

Recommended Posts

If you use this type for one of the columns in a table, what exactly do you get back for that column when you do a query.

 

Is it a string of the format yyyy/mm/dd....... or does the column data get mapped into some sort of data structure that you then interrogate in php code?

 

Also what sort of collation, if any, should you have afor a date column? ascii_bin?

Edited by Greg Boyles
Link to comment
Share on other sites

SQL queries always return strings, Even number data types. PHP has to cast them itself. With numbers you usually don't have to worry about the casting, but with dates you have to parse the string. I think the strtotime() function will work fine.

 

Personally, I store dates as a UNIX timestamp in an INT field in MySQL.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...