In PHP, how can I get the number of seconds until the end of day?
Thanks.
First thought:
86400 - date('H') * 3600 - date('i') * 60 - date('s')
Faster version derived from VolkerK's answer:
strtotime('tomorrow') - time()
$rs = strtotime('24:00') - time();
echo $rs;
edit: even faster
echo mktime(24,0,0) - time();
Here you go! You can specify the timezone too:
$timezone = new DateTimeZone( 'Asia/Kolkata' );
$today = new DateTime('now', $timezone);
$tomorrow = new DateTime('tomorrow', $timezone);
$secondsLeftInTheDay = $tomorrow->getTimestamp() - $today->getTimestamp();
echo $secondsLeftInTheDay;
$sDate = '2014-12-01 23:59:58';
$oDatetime1 = new DateTime($sDate);
$oDatetime2 = new DateTime($sDate);
$oDatetime1->modify( 'tomorrow' );
echo $oDatetime1->getTimestamp() - $oDatetime2->getTimestamp();