Jump to content

Archived

This topic is now archived and is closed to further replies.

michaellunsford

dynamic field "default"?

Recommended Posts

Working on a small calendar project where there is an event date and display dates -- on and off. I have controled this with three fields in mysql: event_date, date_on, and date_off. All of the fields default to 0000-00-00, but I'd like to change that to today's date for date_on, and have date_off default to whatever is sent in event_date (which might not even be possible). One thing's for sure -- refman says I'd have to change all to the timestamp type to do anything like this (and I can only record the current timestamp).

So, is all hopeless in mysql and must be hardcoded in php?

idea:
viewing a particular calendar page could fire something like this
[code]UPDATE `table` SET `date_on` = DATE_ADD(`event_date`, INTERVAL -1 MONTH); WHERE `date_on` = '0000-00-00'[/code]
will that work?

Share this post


Link to post
Share on other sites
Unforutnately, the defaults for columns must be literals, so you can't do it the "easy way". However, the update statement you posted should be just fine (minus the extraneous semi-colon).

Share this post


Link to post
Share on other sites
[!--quoteo(post=374283:date=May 16 2006, 09:28 AM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ May 16 2006, 09:28 AM) [snapback]374283[/snapback][/div][div class=\'quotemain\'][!--quotec--](minus the extraneous semi-colon).
[/quote]

oops -- old habits die hard [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.