get 7 hours back time

Discussion in 'PHP' started by greatlogix, Apr 25, 2011.

  1. #1
    I have date in this format 2011-04-24T05:59:49.000Z I need date/time exact seven hours before this date/time. How I can do this. please help.
     
    greatlogix, Apr 25, 2011 IP
  2. littlejohn199

    littlejohn199 Peon

    Messages:
    42
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try

    $temp_timestamp = strtotime("2011-04-24T05:59:49.000Z");
    $seven_hours_ago = strtotime("-7 hour", $temp_timestamp);

    echo Date("Y-m-d\TH:i:s\Z", $seven_hours_ago);

    Little John
     
    littlejohn199, Apr 25, 2011 IP
    greatlogix likes this.
  3. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This might work (not tested):

    
    $ts = strtotime("2011-04-24T05:59:49.000Z");
    echo sprintf(
        "The time was %s; 7 hours ago it was %s",
        gmdate("Y-m-d H:i:s", $ts),
        gmdate("Y-m-d H:i:s", $ts - 7 * 60 * 60)
    );
    
    PHP:
     
    ap2010, Apr 27, 2011 IP
    greatlogix likes this.
  4. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #4
    Thanks littlejohn199 and ap2010 for your response. I have tested littlejohn199's code and it's working fine. Rep to you both.
     
    greatlogix, Apr 27, 2011 IP