Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between datetime and timestamp

What is difference between datetime and timestamp datatype in Sql Server?.

like image 361
Dr. Rajesh Rolen Avatar asked Dec 16 '10 11:12

Dr. Rajesh Rolen


People also ask

Which is better datetime or TIMESTAMP?

TIMESTAMP is four bytes vs eight bytes for DATETIME . Timestamps are also lighter on the database and indexed faster. The DATETIME type is used when you need values that contain both date and time information. MySQL retrieves and displays DATETIME values in YYYY-MM-DD HH:MM:SS format.

What is the difference between time and TIMESTAMP?

TIMESTAMP: It is also used for values that contain both date and time parts, and includes the time zone. TIMESTAMP has a range of 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. TIME: Its values are in HH:MM:SS format (or HHH:MM:SS format for large hours values). TIME values may range from -838:59:59 to 838:59:59 .

What is the difference between datetime and TIMESTAMP in SQL Server?

Timestamp is a synonym for rowversion, according to the documentation, and it's created automatically and guaranteed1 to be unique. Datetime isn't one of them; it's merely a data type that handles dates and times and may be customised by the client on insert, for example.

Is datetime and TIMESTAMP are same in SQL?

Difference between DATETIME & TIMESTAMP As of MySQL 5.6. 4, DATETIME requires 5 bytes + 3 additional bytes for fractional seconds data storing. In MySQL5+, TIMESTAMP value converts from the current time to UTC and vice-versa while DATETIME does not do any conversion.


2 Answers

One is a date and time, the other is a column type that is updated every time a row is updated.

[Note timestamp is being deprecated; use rowversion instead]

like image 185
Mitch Wheat Avatar answered Oct 04 '22 03:10

Mitch Wheat


Timestamp (deprecated synonym for rowversion) :

Is a data type that exposes automatically generated, unique binary numbers within a database. rowversion is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The rowversion data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime2 data type.

http://msdn.microsoft.com/en-us/library/ms182776.aspx

like image 43
A. M. Avatar answered Oct 04 '22 03:10

A. M.