How to do $date-day

Discussion in 'PHP' started by Adulu, Nov 15, 2008.

  1. #1
    I am echo $date from mysql

    $date=2008-01-02

    how to do "(2008-01-02) - (0000-00-01)"=2008-01-01 in php programming
    is it possible?

    i have try $date=date("$date",Time()-24*3600); but not working.

    help me out
    thank you
     
    Adulu, Nov 15, 2008 IP
  2. arnek

    arnek Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I would suggest using mktime() or strtotime for getting this done

    <?php
    $tomorrow  = mktime(0, 0, 0, date("m")  , date("d")+1, date("Y"));
    $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"),   date("Y"));
    $nextyear  = mktime(0, 0, 0, date("m"),   date("d"),   date("Y")+1);
    ?>
    PHP:
    This will enable you to add and subtracts days, yars, months etc.
     
    arnek, Nov 15, 2008 IP
  3. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #3
    Using strtotime()

    <?
    
    $date='2008-01-02';
    $timestamp = strtotime('-1 day', strtotime($date));
    echo date('Y-m-d',$timestamp);
    ?>
    PHP:
     
    wmtips, Nov 15, 2008 IP