Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > MySQL Ques: How to set default value for date field to be current date

MySQL Ques: How to set default value for date field to be current date
Thread Tools
Dedicated MacNNer
Join Date: Jan 2001
Location: Meida, PA USA
Status: Offline
Reply With Quote
Dec 17, 2002, 11:25 PM
 
I'm trying to convert an ASP/Access tutorial to PHP/MySQL and have a question regarding MySQL.

In Access one can create a date field and set the default to "Date()" to get the current date but according to the mysql manual:

http://www.mysql.com/doc/en/CREATE_TABLE.html
Default values must be constants. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE.
Is there any other way to have MySQL automate this? I've heard of something called stored procedures but am unfamiliar. -- Must this be done on the scripting side?

Thanks.
~ Mike
--
Personal Site: MikeZornek.com
Other Interests: WebDevWiki.com
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Dec 19, 2002, 10:06 AM
 
Not sure what you're aiming to do, but if you want the current date to be placed in the field when the record is created then you just need to add the now() function to the SQL query that creates the row.

For instance something like this:

INSERT INTO table (name, date) VALUES ("name", now());


Then whenever a new record is created, it'll have the current date in the date field.

-tim
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:57 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2