If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > timestamp and datetime

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-06-11, 07:53
chandu123 chandu123 is offline
Registered User
 
Join Date: Nov 2011
Posts: 17
timestamp and datetime

any special advantage of datetime except date range that a timestamp can't???
Reply With Quote
  #2 (permalink)  
Old 12-06-11, 08:49
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
timestamp is the date and time the record was last updated
datetime is a datatype that date and/or time data is stored in
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 12-07-11, 14:43
dm1 dm1 is offline
Registered User
 
Join Date: Dec 2011
Posts: 13
For TIMESTAMP column you can have DEFAULT CURRENT_TIMESTAMP that cannot be specified for DATETIME.

Not a big issue, just another difference between data types. By the way, only one TIMESTAMP column can have this default.

Dmitry

--
http://www.sqlines.com/online - Free SQL conversion between major databases
Reply With Quote
  #4 (permalink)  
Old 12-08-11, 14:40
robcarrol71 robcarrol71 is offline
Registered User
 
Join Date: Dec 2011
Posts: 7
You got the major difference. Storage size is different as a result:

TIMESTAMP uses 4 bytes of storage and can store date from 1970 to 2037

DATETIME uses 8 bytes of storage and can store any date/time from 0000-00-00 00:00:00 to 9999-12-31 23:59:59.

If you are building a time machine, please be sure to use DATETIME.

Last edited by robcarrol71; 12-08-11 at 14:43.
Reply With Quote
  #5 (permalink)  
Old 12-08-11, 14:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by healdem View Post
timestamp is the date and time the record was last updated
doesn't has to be, but this is a very common usage
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 12-08-11, 16:02
dm1 dm1 is offline
Registered User
 
Join Date: Dec 2011
Posts: 13
Quote:
Originally Posted by robcarrol71 View Post
DATETIME uses 8 bytes of storage and can store any date/time from 0000-00-00 00:00:00 to 9999-12-31 23:59:59.
Although DATETIME can store year 0000, the next allowed year is 1000

Dmitry

--
http://www.sqlines.com/online - Free SQL conversion between major databases
Reply With Quote
  #7 (permalink)  
Old 12-08-11, 16:21
robcarrol71 robcarrol71 is offline
Registered User
 
Join Date: Dec 2011
Posts: 7
Quote:
Originally Posted by dm1 View Post
Although DATETIME can store year 0000, the next allowed year is 1000
Oh, very interesting. Thanks for the info
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On