Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Countdown to Date

Tags:

php

How could set a date and get a countdown in PHP? For example if I set the date as 3 December 2PM it would tell me how many days and hours are remaining.

No need for user inputs for the date as it will be hard coded.

Thanks.

like image 964
usertest Avatar asked Nov 14 '09 19:11

usertest


People also ask

How to make a date Countdown in PHP?

You can use the strtotime function to get the time of the date specified, then use time to get the difference. $date = strtotime("December 3, 2009 2:00 PM"); $remaining = $date - time(); $remaining will be the number of seconds remaining. Then you can divide that number to get the number of days, hours, minutes, etc.


1 Answers

You can use the strtotime function to get the time of the date specified, then use time to get the difference.

$date = strtotime("December 3, 2009 2:00 PM");
$remaining = $date - time();

$remaining will be the number of seconds remaining. Then you can divide that number to get the number of days, hours, minutes, etc.

$days_remaining = floor($remaining / 86400);
$hours_remaining = floor(($remaining % 86400) / 3600);
echo "There are $days_remaining days and $hours_remaining hours left";
like image 104
Travis Avatar answered Oct 07 '22 16:10

Travis