tags:

views:

249

answers:

2

I was looking at this post, and it is close to what I need: http://stackoverflow.com/questions/1669165/php-how-to-count-60-days-from-the-add-date

However, in that post, the calculation is performed by adding 60 days to the current date. What I need to do is calculate the date based on a variable date (and not the current date).

Something like this:

$my_date = $some_row_from_a_database;
$date_plus_10_days = ???;

Anyone know how to do that?

Thanks

+10  A: 

You can put something before the "+10 days" part:

strtotime("2010-01-01 +10 days");
Michael Mrozek
+1 learnt a new thing today. Thanks. Probably the OP wants to convert back to some human readable string. So, something like date('Y-m-d',strtotime("2010-01-01 +10 days"));
zaf
`strototime` takes a timestamp as the second argument which will be used as the reference timestamp for what you put as first argument, so if the OP got a timestamp from the MySQL, he can just as well do `strtotime('+60 days', $timestampFromMySql);`
Gordon
perfect - thanks!
OneNerd
+4  A: 

Use date_add

http://www.php.net/manual/en/datetime.add.php

$my_date = new DateTime($some_row_from_a_database);
$date_plus_10_days = date_add($my_date, new DateInterval('P10D'));
jpabluz
You should mention that this is only available from PHP 5.3.0 on.
Felix Kling