stig1 Posted November 18, 2008 Share Posted November 18, 2008 Is it possible to convert a date and time into a string to store in mysql as a varchar and then convert it back to date and time when selected out of the database? If so, how would i go about doing this? Link to comment https://forums.phpfreaks.com/topic/133251-date-time-to-string-to-store-in-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2008 Share Posted November 18, 2008 Store datetime values in a database as a DATETIME data type - http://dev.mysql.com/doc/refman/5.0/en/datetime.html This will result in the least amount of storage space, the fastest executing queries and code, and you can use about 20-30 datetime functions on the values to do about anything you want - http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Link to comment https://forums.phpfreaks.com/topic/133251-date-time-to-string-to-store-in-mysql/#findComment-693021 Share on other sites More sharing options...
stig1 Posted November 18, 2008 Author Share Posted November 18, 2008 I have always stored my dates and times in date and time fields, however someone told me that its smaller database sizes, if u store them in strings. Link to comment https://forums.phpfreaks.com/topic/133251-date-time-to-string-to-store-in-mysql/#findComment-693027 Share on other sites More sharing options...
Mchl Posted November 18, 2008 Share Posted November 18, 2008 He told you wrong. Unless he was talking about MySQL server version lower than 4.1, where he could be right in some cases. Other than that, DATE and TIME are best for storing dates and times respectively. Look here: http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html DATE and TIME take up 3 bytes each. I dare you to store date as a string in less than 3 bytes Link to comment https://forums.phpfreaks.com/topic/133251-date-time-to-string-to-store-in-mysql/#findComment-693030 Share on other sites More sharing options...
PFMaBiSmAd Posted November 18, 2008 Share Posted November 18, 2008 Rather than listening to someone else, why not figure it out for yourself - Data Type..... Storage Required DATE............ 3 bytes TIME............ 3 bytes DATETIME..... 8 bytes TIMESTAMP... 4 bytes YEAR............ 1 byte VARCHAR(M), VARBINARY(M) L + 1 bytes if column values require 0 – 255 bytes, L + 2 bytes if values may require more than 255 bytes For a yyyy-mm-dd hh:mm:ss - DATETIME..... 8 bytes VARCHAR ......20 bytes Link to comment https://forums.phpfreaks.com/topic/133251-date-time-to-string-to-store-in-mysql/#findComment-693034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.