SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2010
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with substracting time from variable

    I want to echo the date of today minus 1 day, how do I do this?

    I am thinking its something like - needs to be in human readable format.

    PHP Code:
    $yesterday time() - 1;

    echo 
    $yesterday
    but that doesnt work

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,033
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    time() is in seconds, not in days

    So, $yesterday = time() - 24 * 3600, or in PHP >= 5.3 $yesterday = new \DateTime('-1 day');

    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

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