Jump to content

Incrementing an entered date


newburcj

Recommended Posts

I have a form with two text fields:

Date the show will open: $_POST['vdate'] (not the current date)

and

Number of performances: $_POST['shows']

 

vdate is entered in the format 'yyyy-mm-dd'.

 

I would like to take the original vdate, enter its value into a MySQL field, and increment the date by one day in a loop until the value of shows is reached. The loop isn't my problem. I can't seem to increment the date within the loop. There's a lot of date functions within php but none of them seem to be able to do this simple addition: newdate = date + 1 day. Help would be appreciated as I'm totally stuck.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/199347-incrementing-an-entered-date/
Share on other sites

I finally figured out the code needed:

 

<?php

$TZ = date_default_timezone_set("America/New_York"); \\ if not already set.

$oldate = '2010-05-10';

$dd = strtotime($oldate) + 86400;

$newdate =  date("Y-m-d",$dd);  \\ newdate becomes '2010-05-11'

?

 

Thanks! ;D

I finally figured out the code needed:

 

<?php

$TZ = date_default_timezone_set("America/New_York"); \\ if not already set.

$oldate = '2010-05-10';

$dd = strtotime($oldate) + 86400;

$newdate =  date("Y-m-d",$dd);  \\ newdate becomes '2010-05-11'

?

 

Thanks! ;D

 

$newdate = strtotime('2010-05-10' . " +1 days");

Archived

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

×
×
  • Create New...

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.