How to get the UNIX timestamp range of the current hour, i mean one of the first second and the other for the last second. so if it's 18:45 i would get the timestamp of 18:00 and 18:59.
Thanks
How to get the UNIX timestamp range of the current hour, i mean one of the first second and the other for the last second. so if it's 18:45 i would get the timestamp of 18:00 and 18:59.
Thanks
You can get the components of the current time with getdate()
, and use mktime()
to find the timestamps:
$date = getdate();
$start = mktime($date['hours'], 0, 0);
$end = $start + (60*60);
You can also use date()
, which is slightly simpler:
$start = mktime(date("H"), 0, 0);
$end = $start + (60*60);
$start = mktime(date('H'), 0, 0);
$end = mktime(date('H'), 59, 59);
Could be generalized for any timestamp, not just the current time, as:
$time = time(); // some timestamp
$start = mktime(date('H', $time), 0, 0, date('n', $time), date('j', $time), date('Y', $time));
$end = mktime(date('H', $time), 59, 59, date('n', $time), date('j', $time), date('Y', $time));