1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Timestamp for today -> end of today

Discussion in 'PHP' started by Aids, Dec 24, 2010.

  1. #1
    Hey guys,

    I want to find the timestamp at the start of a particular date to the end of that day.
    i.e. 00:00:00am-11:59:59pm

    How would I do this. For example if I had the date 02:02:2009 (2nd february 2009) how would I get the starting and ending timestamp.
    SEMrush
    Thanks
     
    Solved! View solution.
    Aids, Dec 24, 2010 IP
    SEMrush
  2. naskin

    naskin Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use PHP function mktime
     
    naskin, Dec 24, 2010 IP
  3. #3
    
    // Start of today's server time
    echo strtotime(date("Y-m-d 00:00:01"));
    // End of today's server time
    echo strtotime(date("Y-m-d 23:59:59"));
    
    PHP:
     
    ThePHPMaster, Dec 24, 2010 IP
  4. Aids

    Aids Peon

    Messages:
    195
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    @ThePHPMaster - Thanks! It works brilliantly
     
    Aids, Dec 25, 2010 IP
  5. Aids

    Aids Peon

    Messages:
    195
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'm trying to get the timestamp of a date 10 days ago. I got this so far and it works if the date is less than 10 (it will decrease the month by one) but it doesn't work for years - i've just noticed this because of the new year.

    
    $daydate = date("d");
    $monthdate = date("m");
    $yeardate = date("Y");
    
    $day_10 = ($daydate - 10);
    $daydate10 = $yeardate . "-" . $monthdate . "-" . $day_10;
    $daydate10_start = strtotime(date("$daydate10 00:00:00"));
    $daydate10_end = strtotime(date("$daydate10 23:59:59"));
    
    PHP:
    Anyone know of any functions to do the same thing as this but works for any date?
     
    Aids, Jan 2, 2011 IP
  6. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #6
    You can get a date 10 days ago as such, if that's what you mean:

    
    $ten_days_ago = time()-(86400*10);
    $format = date("M d Y h:i:s", $ten_days_ago);
    
    Code (markup):
     
    Cozmic, Jan 2, 2011 IP
  7. Aids

    Aids Peon

    Messages:
    195
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for your reply cozmic but if the current time is 5:00 on the 3rd Jan 2010 then it'll give me the timestamp of 5:00 on the 24th December but i want the time 0:00 on the 24th december.
    Also, I want date to timestamp, not timestamp to date.

    Anyway thanks for your help.
     
    Aids, Jan 2, 2011 IP
  8. Alex Roxon

    Alex Roxon Active Member

    Messages:
    424
    Likes Received:
    11
    Best Answers:
    7
    Trophy Points:
    80
    #8
    $days = -10; // Ten days ago
    $timestamp = strtotime( date( "Y-m-d 00:00:01", time() + ( 86400 * $days ) ) ) ;
    PHP:
    Try that
     
    Alex Roxon, Jan 2, 2011 IP