Jump to content

strtotime - how to...


nudo01

Recommended Posts

So, my problem is that I need to edit my Xmas calculator to understand when this year's Xmas is over, it will automatically jump to the next one (2011-12-25).

 

I have no idea how to do this (noob to php...)

 

Thanks in advance.

 

Here's my code:

<?php
$time=time();
$xmas=strtotime("2010-12-25 00:00:00");
$diff = $xmas - $time;
$days=intval($diff/86400);
$left=$diff%86400;

$hs=intval($left/3600);
$left=$left%3600;

$mins=intval($left/60);
$secs=$left%60;

echo "<font size=12 face=corbel>
Xmas is after:<br>
<strong>$days days</strong><br>
<strong>$hs hours</strong><br>
<strong>$mins mins $secs secs</strong>!
</font>";
?>

Link to comment
https://forums.phpfreaks.com/topic/217554-strtotime-how-to/
Share on other sites

I didn't check your breakdown of months/days/minutes/seconds, but you can use this snippet to find the year of the next Christmas: (Works from 2010 and onward)

 

$now = time();
$year = 2010;

while (strtotime($year . '-12-25') < $now) {
  $year++;
}

// $year is now the year of the next christmas

Link to comment
https://forums.phpfreaks.com/topic/217554-strtotime-how-to/#findComment-1129389
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.