Sam
Sam

Reputation:

Add date/time to MySQL table?

How can I add the current date and time (the date and time set on the server) to a MySQL table?

Upvotes: 2

Views: 24465

Answers (4)

terrific
terrific

Reputation: 1667

use timestamp. easiest way, current_timestamp

Upvotes: 0

mpen
mpen

Reputation: 282885

Pretty sure there's a NOW() function... link

Upvotes: 11

MarkusQ
MarkusQ

Reputation: 21950

Do you want to add it to the table or just to the result set? You can add NOW() to the field list of any query to do that.

If you just want to know what time the server thinks it is try:

SELECT NOW();

Edit: the original of this answer erroneously used "GETDATE()" 'cause I totally missed the MySQL tag. Matt Solnit called me on it, and rightly so.

Upvotes: 4

Scott Ferguson
Scott Ferguson

Reputation: 7830

CREATE TABLE t (ts TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

Upvotes: 1

Related Questions