Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts

    print time yesteraday 7am and today 7am in UNIX timestamp

    I have to two variables $cronlast and $cronnow in my php code.
    I need to have the time 7am of previous day in $cronlast variable and 7am today in $cronnow variable.
    I need the time in UNIX timestamp format.
    So everyday when I print the variable I should have:

    $cronlast=7am Yesterday(in Unix Timestamp)
    $cronnow=7am Today(in Unix Timestamp)

    I would appreciate any help.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    http://www.php.net/strtotime
    PHP Code:
    $cronlast strtotime'yesterday 7:00 AM' );
    $cronnow  strtotime'today 7:00 AM' ); 

  • #3
    Regular Coder
    Join Date
    Aug 2011
    Posts
    134
    Thanks
    20
    Thanked 0 Times in 0 Posts
    thanks

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    strtotime can do that:
    PHP Code:
    $todayAt7 strtotime('07:00');
    $yesterdayAt7 strtotime('yesterday 07:00'); 
    Edit:
    Not even a close beat today :P


  •  

    Tags for this Thread

    Posting Permissions

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