Home » Blogging

PHP: Add a number of days to a date

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 Posts with Thumbnails

One Comment »

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