GetDate() Equivalent for MySQL DB

Hello,

in MS SQL there is a command that I can issue where when used as the default value for
the fields (DateTime datatype) will generate date & time value when a new row is inserted.

CREATE TABLE [TBL_TABLE](
 [fldDATE] [datetime] NULL DEFAULT (GetDate())
 )
GO

What would be the equivalent of GetDate() for MySQL ? How can I set a field in a table to generate
the current date when a new row is inserted ? Thanks !

vpekulasAsked:
Who is Participating?
 
todd_farmerCommented:
Here's a relevent example from the above link:

CREATE TABLE t (ts TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
                             DEFAULT CURRENT_TIMESTAMP);
0
 
todd_farmerCommented:
To define a default value for a date/time related column, you need to use TIMESTAMP:

http://dev.mysql.com/doc/refman/5.0/en/timestamp-4-1.html
0
 
BogoJokerCommented:
Hi vpekulas,

NOW(), CURRENT_TIMESTAMP(), CURRENT_TIME(), CURRENT_DATE(), CURTIME()
'' <-- Will automatically do NOW() in a DATE field

Here are all of them, you should definantly read over this page, its got it all!:
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Joe P
0
 
BogoJokerCommented:
Whoop, you snuck in there todd =)
Use todd's example its perfect for you.
Make sure you checkout the mysql docs we both posted.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.