Jump to content

Best way to format a date for storage in MySQL


ATLChris

Recommended Posts

There are 2 options, use an integer timestamp or a date timestamp.

Either way your columns will be  INTEGER or DATETIME.

 

Now, there is a problem with using the built in NOW() and CURRENT_TIMESTAMP options in MySQL, and that's that they don't adhere to DST. Meaning you could end up hitting a date on the wrong side of DST. Thus while I DO condone the usage of CURRENT_TIMESTAMP and the TIMESTAMP field type, I recommend that you utilise the strtotime() function from PHP to generate a timestamp in INTEGER format, and if you prefer to have DATETIME's in your DB then use:

date('Y-m-d H:i:s', strtotime("NOW"));

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.