Jump to content

Date / Time to String to store in MySQL


stig1

Recommended Posts

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

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 :P

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

 

 

 

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.