quick php date help..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxweekxx
    Confirmed User
    • Oct 2002
    • 6780

    #1

    quick php date help..

    <?php
    echo date("m/d/y");
    ?>

    that will echo current month/day/yr

    how do i make it echo YESTERDAYs info

    so instead of 04/06/10

    it'l be 04/05/10
    _________________
    I am the best
  • ottopottomouse
    She is ugly, bad luck.
    • Jan 2010
    • 13177

    #2
    $yesterday=date("m/d/y", time()-86400);

    carry on multiplying the seconds to get back more days
    ↑ see post ↑
    13101

    Comment

    • xxweekxx
      Confirmed User
      • Oct 2002
      • 6780

      #3
      so it'll be

      <?php
      $yesterday=date("m/d/y", time()-86400);
      ?>
      _________________
      I am the best

      Comment

      • natkejs
        Confirmed User
        • Jan 2003
        • 1640

        #4
        or

        <?php
        echo date("m/d/y",mktime(0,0,0,0,-1,0));
        ?>

        that tells it to generate a date using todays date -1 day, so that would be yesterday.
        change -1 to -7 and it will be one week ago and so on and so forth...

        Comment

        • Brujah
          Beer Money Baron
          • Jan 2001
          • 22157

          #5
          Take a look at strtotime also, if you prefer. You can do a lot with it like; +1 day, -1 day, last monday, next tuesday, etc...
          http://www.php.net/manual/en/function.strtotime.php

          $yesterday = date('m/d/y', strtotime('-1 day'));

          Comment

          • natkejs
            Confirmed User
            • Jan 2003
            • 1640

            #6
            Originally posted by Brujah
            Take a look at strtotime also, if you prefer. You can do a lot with it like; +1 day, -1 day, last monday, next tuesday, etc...
            http://www.php.net/manual/en/function.strtotime.php

            $yesterday = date('m/d/y', strtotime('-1 day'));
            very neat, never used it like that

            Comment

            Working...