Search code examples
phpdatetime

php get future date time


I don't know how to explain this correctly but just some sample for you guys so that you can really get what Im trying to say.

Today is April 09, 2010

7 days from now is April 16,2010

Im looking for a php code, which can give me the exact date giving the number of days interval prior to the current date.

I've been looking for a thread which can solve or even give a hint on how to solve this one but I found none.


Solution

  • If you are using PHP >= 5.2, I strongly suggest you use the new DateTime object, which makes working with dates a lot easier:

    <?php
    $date = new DateTime("2006-12-12");
    $date->modify("+7 day");
    echo $date->format("Y-m-d");
    ?>