What is the best datatype for DATE and TIME

I have an application that stores the date and time of a transaction. My initial database project is to create separate fields for DATE

as date and TIME

as varchar. My second option is to have one field with DATETIME

.

What is the difference between the two?

+3


source to share


3 answers


I would recommend using TIMESTAMP as it will help you keep track of all changes made to your database. You must use the DateTime datatype if you want to store a specific datetime value in your column. But if you want to keep track of the changes made to your values, I would recommend using TIMESTAMP. From MYSQL Docs :



The DATETIME type is used when you need values ​​that contain date and time information. MySQL retrieves and displays DATETIME values ​​in the format "YYYY-MM-DD HH: MM: SS". The supported range is "1000-01-01 00:00:00" to "9999-12-31 23:59:59".

...

The TIMESTAMP data type has the range '1970-01-01 00:00:01' UTC to '2038-01-09 03:14:07' UTC. It has different properties depending on the MySQL version and the SQL mode the server is running on.

+2


source


Use a timestamp. I would advise not to store the date and time separately. The reason is that when you want to use them in a where clause, you can add them together.



+1


source


datetime will indicate the date and time at which the broadcast was made 12-10-2012 12:00:00 So instead of using two separate fields, we can use one, i.e. datetime

0


source







All Articles