Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch timestamp of the midnight before a given timestamp

Tags:

php

timestamp

Given any unix-timestamp T, I want to fetch the timestamp of the midnight before T.

The given timestamp can be any integer: now, today, (not too far[]) in the future or (not too far[]) in the past.

Is there a cleaner way then (pseudocode):

<?php
$midnight = strtotime("{date('d',$ts)}-{date('m',$ts)}-{date('Y', $ts)} midnight");
?>

Thanks.

[*] somewhere between 1990 and 2020.

like image 463
berkes Avatar asked Dec 27 '22 11:12

berkes


1 Answers

I would do it as

$midnight = strtotime(date('Y-m-d',$ts).' 00:00:00');

...but whether that is cleaner/better is debatable...

like image 145
DaveRandom Avatar answered Jan 05 '23 17:01

DaveRandom