Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can MySQL auto-fill a date field like SQL Server?

Status
Not open for further replies.

deeshubby

Programmer
Jul 10, 2001
33
US
I'm a newbie to MySQL and am trying to make a date field have a default value of the current date.

In Microsoft SQL Server you just supply default value of "getDate()" and SQL Server takes care of populating the field whenever new entries are made to the table.

I searched this forum, and there's not a lot written about MySQL date stuff... anyone know? Thanks...
 
SELECT CURDATE() will get you the current date, so you just fill your date field with the resultant query.

sipps
 
Mysql, for some reason beyond me, does not support using current_date as default.

One solution is to use a timestamp column. A timestamp column is set when a new value is inserted or the table is updated.
If you have two timestamp columns in the table, only the first is changed on update, thus it is possible to have both the entrydate and the modification maintained automatically (but not the entrydate only).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top