phptimestamp

Get timestamp of today and yesterday in php


How can I get the timestamp of 12 o'clock of today, yesterday and the day before yesterday by using strtotime() function in php?

12 o'clock is a variable and would be changed by user.


Solution

  • $hour = 12;
    
    $today              = strtotime($hour . ':00:00');
    $yesterday          = strtotime('-1 day', $today);
    $dayBeforeYesterday = strtotime('-1 day', $yesterday);