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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.