Adding days to a date value and inserting the new value into a date field

18 posts by 3 authors in: Forums > CMS Builder
Last Post: February 11, 2015   (RSS)

By northernpenguin - January 16, 2015

Jerry:  have you tried using the following SQL:

UPDATE tablename SET fieldname1 = fieldname2 + INTERVAL 7 DAY;

I have used it with + 1 YEAR.  You may need to check the syntax to confirm is "DAY"

So you should be able to do this:

UPDATE tablename SET removeDate = event_end_date + INTERVAL 7 DAY;

Tell me if it works!

Ragi

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By gkornbluth - January 16, 2015 - edited: January 16, 2015

Hi Ragi,

Appreciate your looking at this.

I'm not too good at mysql syntax. Where would you insert that code in the above?

Thanks,

Jerry Koirnbluh

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By northernpenguin - January 16, 2015 - edited: January 16, 2015

Jerry:  You had to ask the hard question!

That is exactly what i am working on in my database.  For now, I used phpMyAdmin to do it manually.

As soon as I figure it out I will respond to the post.

Ragi

P.S.  BTW, have you every heard of phpGrid? (http://phpgrid.com)  Worth a look.

--
northernpenguin
Northern Penguin Technologies

"Any sufficiently advanced technology
is indistinguishable from magic."
........Arthur C. Clarke

By gkornbluth - January 16, 2015

Looking forward to the answers..

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By claire - January 19, 2015

Hey Jerry, try this:

$end_date_plus_7_days = date('Y-m-d H:i:s', strtotime($event_end_date) + 60*60*24*7); 

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - January 19, 2015 - edited: January 19, 2015

Thank you Claire,

That works perfectly.

It's so easy when you know how....

Best,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gkornbluth - January 19, 2015

Hi Claire,

I feel like I'm pushing my luck by asking, but is there an easy way to add one year (or 2 years) to the expiresDate to a specific date without a long string of multiplication operatives?

Possibly one that takes into account that dreaded leap year calculation?

So for example, if a membership cycle is Oct 1 - September 30, and someone renews in the first half of the cycle (October 1 - March 31), they get renewed through September 30 of the next year.

If they renew in the second half of the cycle (On or after April 1) they get renewed through September 30 of the second year.

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By claire - January 20, 2015

No easy way that I know of, sorry Jerry. It's definitely possible, but it'd be a custom function to check if February 29th falls within the bounds of the added time.

Adding time using the UNIX timestamp and a string of multiplication is really the simplest method of doing it, unfortunately.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By gkornbluth - January 20, 2015

Thanks Claire,

Could I use Sept 30 as a fixed value and add 1 or 2 to the year value depending on which part of the year they renewed in?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php