How can I add the current date and time (the date and time set on the server) to a MySQL table?
+1
A:
CREATE TABLE t (ts TIMESTAMP ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
Scott Ferguson
2009-04-01 23:46:10
A:
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.
MarkusQ
2009-04-01 23:47:31
The GETDATE() function does not exist in MySQL.
Matt Solnit
2009-04-01 23:49:38
My bad. I've gotten so used to all the MS* questions here I just missed the tag.
MarkusQ
2009-04-02 00:59:57
That's what I figured ;-)
Matt Solnit
2009-04-02 01:09:09
Yeah, this is the answer.. More on this @ http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_now
Tim
2009-04-02 01:10:50