Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    19

    Unanswered: how to add days to a specific date in PHP

    Hi,

    I just need to do the following date calculation:

    2004-12-12 + 2 = 2004-12-14

    thats all.


    remember: 2004(year)-12(month)-2(day)
    I just need to add days to a specific date. No the current date.

    Even that is so simple I cant find nothing in the web. Theres a lot for calculte using the current date. Thats not what I need.

    check this:

    $timestamp = strtotime("+2 day");
    $tomorrow=strftime( "%Y-%m-%d",$timestamp);

    echo $tomorrow; /* This give me the one day after the current day */

    fe example: supost today is 2004-09-06 this will give me 2004-09-07

    Thats nice, but what I want is to use instead of the current date, a specific date, any date I want.

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    This would be one of the examples that may server your purpose.
    $timestamp=time(); //current timestamp
    echo "Current Time: $timestamp<br>";
    $tm=$timestamp+172800; // Will add 2 days to the $timestamp
    $da=date("F j, Y, g:i a", $timestamp);
    echo "Current time string: $da <br>";
    $da1=date("F j, Y, g:i a", $tm);
    echo "Modified time: $da1 <br>";

    Regards
    Rajesh

  3. #3
    Join Date
    Aug 2004
    Location
    San Antonio, TX
    Posts
    84
    Check the DATE_ADD() function in the manual. If you're running MySQL 5, you can also check the TIMESTAMPADD() function.

  4. #4
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    check this method, will this do?
    function datetime($diff)
    {
    $timestamp=time();
    $tm=86400*$diff;
    $tm=$timestamp+$tm;
    return $tm;
    }
    $dtm=2; // This is the no of days to be added to the given timestamp $timestamp
    $tm1=datetime($dtm);
    $da = date("F j, Y, g:i a", $tm1);
    echo "Date $da <br>"; //The added date

    You can make little more changes to the code and can make it as you wish

    Regards
    Rajesh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •