[SOLVED] adding a date in

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

[SOLVED] adding a date in

Post by nutstretch »

I want to automatically add the today's date into a field on my database for DateEntered.

In access I just use the date() function as the default value in the field. Is there a similar function for mysql?

if not i can enter it when the other data is enterered but am unsure of the syntax. when i tried getdate() id didn't work do I need to put anything in the () part or am i completely barking up the wrong tree/

Any help appreciated
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Check out the mysql manual. The correct column type will add the current date automatically when a new row is created - you won't need to enter anything.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

nutstretch
Forum Contributor
Posts: 104
Joined: Sun Jan 11, 2004 11:46 am
Location: Leicester

Post by nutstretch »

Thanks I also realised I was using the wrong datatype. changed the field to timestamp and it auitomatically gets entered.
rajshekhar
Forum Newbie
Posts: 1
Joined: Fri Jan 16, 2004 5:57 am
Location: India
Contact:

Post by rajshekhar »

Small answer check out http://www.mysql.com/doc/en/DATETIME.html . Long answer, make a column of type TIMESTAMP. The TIMESTAMP column type provides a type that you can use to automatically mark INSERT or UPDATE operations with the current date and time. If you have multiple TIMESTAMP columns, only the first one is updated automatically.
Post Reply