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 gkornbluth - January 16, 2015

Hi All,

I’m trying to use one date value in a form to insert 2 date values into a new record. The date fields are called event_end_date and removeDate.

If an event_end_date is entered in the form, on submission I want to:
A)  enter that date in the event_end_date field
B)  add 7 days to that date and enter the new date into the removeDate field

*** I can’t figure out how Accomplish step “B”

Thanks for your help,

Jerry Kornbluth
 
Here’s the code I’m using so far.

Near the top of the page to define variables:

 $event_end_date = date("Y-m-d",mktime(0,0,0,@$_REQUEST['month_2'],@$_REQUEST['day_2'],@$_REQUEST['year_2']));  //Works to populate the event_end_date field

And, I’ve tried both:

$end_date_plus_7_days =date("Y-m-d", strtotime($event_end_date . " +7 day");
and
$end_date_plus_7_days = strtotime(date("Y-m-d", strtotime($event_end_date)) . " +7 day");

but neither work to populate the removeDate field


In my mysql insert I’m using:

event_end_date    = '".mysql_escape($event_end_date)."',
and
removeDate     = '".mysql_escape($end_date_plus_7_days)."',



And in the form I'm using:

<tr>
              <td class="body-text-bold-9">Event End Date</td>
              <td> Month:
                <select name="month_2">
                  <?php foreach(range(1,12) as $month_2): ?>
                  <option value="<?php echo $month_2;?>"><?php echo date("F",strtotime("0000-$month_2"));?></option>
                  <?php endforeach ?>
                </select>
                Day:
                <select name="day_2">
                  <?php foreach(range(1,31)as $day_2): ?>
                  <option value="<?php echo $day_2;?>"><?php echo $day_2;?></option>
                  <?php endforeach ?>
                </select>
                Year:
                <select name="year_2">
                  <?php foreach (range($lowestYear,$highestYear) as $year_2):?>
                  <option value="<?php echo $year_2;?>"><?php echo $year_2;?></option>
                  <?php endforeach?>
                </select></td>
            </tr>

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 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