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.

 
Go Back  dBforums > Database Server Software > MySQL > Help Please. Trying to add 1 Year onto a Date.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-11-09, 20:53
se7enhu se7enhu is offline
Registered User
 
Join Date: Jun 2009
Posts: 1
Help Please. Trying to add 1 Year onto a Date.

Hey guys, I got a table called members and Im trying to set up a trigger to add 1 YEAR onto a DATE when someone adds a new record. The SQL Command I've been trying is:

Quote:
CREATE TRIGGER setResigned
BEFORE INSERT ON members
FOR EACH ROW
BEGIN
SET NEW:dateResigned = DATE_ADD(NEW:dateJoined,INTERVAL 1 YEAR);
END;
I've been messing with this for two days, read the MySql documentation, search all over the net, no avail.

Please help. Thanks.

Last edited by se7enhu; 06-11-09 at 20:56.
Reply With Quote
  #2 (permalink)  
Old 06-12-09, 04:52
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Quote:
Originally Posted by se7enhu
Hey guys, I got a table called members and Im trying to set up a trigger to add 1 YEAR onto a DATE when someone adds a new record. The SQL Command I've been trying is:



I've been messing with this for two days, read the MySql documentation, search all over the net, no avail.

Please help. Thanks.
Why do it in a trigger? they just make your application more complicated and hide functionality. Why not just do it in the original insert ie :
Code:
insert members ( ... , dateResigned ) 
values ( ..., date_add( now(), interval 1 year ) );
The other question is do people always resign after 1 year? If so then why store dateResigned, why not just calculate dateResigned from the date joined.

Mike
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting 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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On