?
Solved

GetDate() Equivalent for MySQL DB

Posted on 2006-04-11
4
Medium Priority
?
64,671 Views
Last Modified: 2011-08-18
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 !

0
Comment
Question by:vpekulas
  • 2
  • 2
4 Comments
 
LVL 30

Expert Comment

by:todd_farmer
ID: 16432506
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
 
LVL 30

Accepted Solution

by:
todd_farmer earned 1000 total points
ID: 16432509
Here's a relevent example from the above link:

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

Expert Comment

by:BogoJoker
ID: 16432515
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
 
LVL 17

Expert Comment

by:BogoJoker
ID: 16432522
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question