let’s create a php function that counting down towards certain event. in this case we will be counting down towards new year in 2017.
<?php $target = mktime(0, 0, 0, 1, 1, 2017) ; $today = time () ; $difference =($target-$today) ; $days =(int) ($difference/86400) ; print "new year is in $days days"; ?>
Here’s the code explanation
First we have to set our target date toward new year
$target = mktime(0, 0, 0, 1, 1, 2017) ;
We also need to know today’s date. We can do that using the time function:
$today = time () ;
Next we subtract to calculate the difference between our target date (new year) and today’s date.
$difference =($target-$today) ;
so in one day there are 86400 seconds so we divided the $difference with the amounts of seconds in a day and convert it into an integer.
$days =(int) ($difference/86400) ;
and you can see the result in here