tags:

views:

88

answers:

4

Hi,

I need to find a date after a certain number of weeks. For example, if the start date is Saturday, 31 October 2009, and if I choose 16 weeks then I need to find the date after sixteen Saturdays.

Thanks in advance.

A: 

Why not just use unix time, subtract 7 * 24 * 3600 * 16 from that and then convert that back into the date that you need.

This will help with the conversion back: http://php.net/manual/en/function.date.php

James Black
+1  A: 

If you're using PHP 5.2.0 or later, you can use the DateTime class

<?php
$date = new DateTime('31 October 2009'); // This accepts any format that strtotime() does.

// Now add 16 weeks
$date->modify('+16 weeks');

// Now you can output it however you wish
echo $date->format('Y-m-d');
?>
Jason
+4  A: 

You can use strtotime:

// Oct 31 2009 plus 16 weeks
echo date('Y-m-d', strtotime('2009-10-31 +16 week')); // outputs 2010-02-20


// next week
echo date('Y-m-d', strtotime('+1 week')); // outputs 2009-11-07
CMS
+1  A: 

strtotime() is what you want: it takes an expression and turns it into a date object. Also see date():

$date = '31 october 2009';
$modification = '+ 16 weeks';
echo date('Y-m-d (l)', strtotime("$date")); //2009-10-31 (Saturday)
echo date('Y-m-d (l)', strtotime("$date $modification")); // 2010-02-20 (Saturday)
artlung