Daily Technology News, Tips, and Reviews | Subscribe to Jason Slater Technology BlogTechnology Feed | Join Jason Slater on TwitterTwitter | Thursday 2nd September 2010

PHP: Add a number of days to a date

By Jason Slater
  • DiggThis
  • Share

example code to add a number of days to a date

// add 5 days
$daystoadd=5;
// calculate hours
$hours=$daystoadd * 24;
// get today
$dd=date(d);
$mm=date(m);
$yy=date(y);
// calculate the new date
$newdate=date("d-m-y", mktime($hours, 0, 0, $mm, $dd, $yy));
// show the new date
echo "The new date is: " . $new;

Related

One comment so far

  • c mktime says:

    [...] today dd=dated mm=datem yy=datey // calculate the new date newdate=date&quotd-m-y&quot, mktimehours,http://www.sl8r.co.uk/2008/04/11/php-add-a-number-of-days-to-a-date/mktimeMKTIME.C: The example takes a number of days * as input and returns the time, the current * [...]

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.