In PHP, how can I get the number of seconds until the end of the day?
Thanks.
First thought:
86400 - date('H') * 3600 - date('i') * 60 - date('s')
Faster version derived from VolkerK answer:
strtotime('tomorrow') - time()
$rs = strtotime('24:00') - time(); echo $rs;
edit: even faster
echo mktime(24,0,0) - time();
$sDate = '2014-12-01 23:59:58'; $oDatetime1 = new DateTime($sDate); $oDatetime2 = new DateTime($sDate); $oDatetime1->modify( 'tomorrow' ); echo $oDatetime1->getTimestamp() - $oDatetime2->getTimestamp();
If you use Carbon , you can just use
Carbon::now()->secondsUntilEndOfDay();