Last active
September 20, 2016 07:30
-
-
Save wzulfikar/acbb16cc2c8aaa4a03e9394078a96688 to your computer and use it in GitHub Desktop.
Get seconds difference from current time to given time. Will always compare closest time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function diffTo($toTime) | |
{ | |
$now = strtotime('now'); | |
$next = strtotime('today ' . $toTime); | |
if($next <= $now){ | |
$next = strtotime('tomorrow ' . $toTime); | |
} | |
return $next - $now; | |
} | |
// example | |
$nextTime = '13.19'; | |
echo 'current time is ' . date('Y-m-d H:i:s'); | |
echo '<br/>'; | |
echo 'next time is ' . $nextTime; | |
echo '<br/>'; | |
echo 'diff to next time in minutes: ' . round(diffTo($nextTime) / 60, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment