Reputation:
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
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
Reputation: 7830
CREATE TABLE t (ts TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Upvotes: 1