Get seconds to the end of the day in PHP

In PHP, how can I get the number of seconds until the end of the day?

Thanks.

+7
php
source share
4 answers

First thought:

86400 - date('H') * 3600 - date('i') * 60 - date('s') 

Faster version derived from VolkerK answer:

 strtotime('tomorrow') - time() 
+29
source share
 $rs = strtotime('24:00') - time(); echo $rs; 

edit: even faster

 echo mktime(24,0,0) - time(); 
+7
source share
 $sDate = '2014-12-01 23:59:58'; $oDatetime1 = new DateTime($sDate); $oDatetime2 = new DateTime($sDate); $oDatetime1->modify( 'tomorrow' ); echo $oDatetime1->getTimestamp() - $oDatetime2->getTimestamp(); 
0
source share

If you use Carbon , you can just use

Carbon::now()->secondsUntilEndOfDay();

0
source share

All Articles