ATLChris Posted February 10, 2009 Share Posted February 10, 2009 What would be the best way to store a date in a MySQL database? i.e. 20090209? 02092009? Unix Timestamp? Link to comment https://forums.phpfreaks.com/topic/144558-best-way-to-format-a-date-for-storage-in-mysql/ Share on other sites More sharing options...
dreamwest Posted February 10, 2009 Share Posted February 10, 2009 Almost.. 2009-02-10 And update with $sql = "UPDATE date SET adddate='".date( "Y-m-d" )."'; mysql_query($sql) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/144558-best-way-to-format-a-date-for-storage-in-mysql/#findComment-758626 Share on other sites More sharing options...
PFMaBiSmAd Posted February 10, 2009 Share Posted February 10, 2009 Use a DATE data type - http://dev.mysql.com/doc/refman/5.1/en/date-and-time-type-overview.html Link to comment https://forums.phpfreaks.com/topic/144558-best-way-to-format-a-date-for-storage-in-mysql/#findComment-758629 Share on other sites More sharing options...
aschk Posted February 10, 2009 Share Posted February 10, 2009 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")); Link to comment https://forums.phpfreaks.com/topic/144558-best-way-to-format-a-date-for-storage-in-mysql/#findComment-758837 Share on other sites More sharing options...
fenway Posted February 15, 2009 Share Posted February 15, 2009 Is that true even if you've set the server/client time zones appropriately? I haven't tried... Link to comment https://forums.phpfreaks.com/topic/144558-best-way-to-format-a-date-for-storage-in-mysql/#findComment-762679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.