Jump to content

Recommended Posts

ok so; let me give you an example

 

<?php
$doy = date(("z"), time() - (14400 * 1));
$calculate = 365 - $doy;
$currentyear = date(("Y"), time() - (14400 * 1));
$output = $currentyear + 1;

if ($calculate == 0)
{
echo "Happy New Year";
}
else if ($calculate <= 365)
{
echo "There are $calculate days left until $output.";
}
?>

 

Now I know I probably could set up code to check for leap year. But the question now posed, is will leap year automatically be configured into the 365 or will I have to create some code too look for leap year; that will add 365 + 1 (or something like that), if leap year occurs?

Thanks for the help dustinnoe and kenrbnsn; I came up with a little bit of a different solution.

 

 

<?php

$check4leap = date(("L"), time() - (14400 * 1));

if ($check4leap == 1) {
$daysNyear="366";
}
else {
$daysNyear="365";
}

$doy = date(("z"), time() - (14400 * 1));
$calculate = $daysNyear - $doy;
$currentyear = date(("Y"), time() - (14400 * 1));
$output = $currentyear + 1;

if ($calculate == 0)
{
echo "Happy New Year";
}
else if ($calculate <= $daysNyear)
{
echo "There are $calculate days left until $output.";
}
?>

Here is a more simplified solution

 

<?php
$doy = date(("z"), time() - (14400 * 1));
$currentYear = date(("Y"), time() - (14400 * 1));
$lastDay = strtotime("Dec 31, $currentYear");
$numDays  = date('z', $lastDay);
$daysTil = $numDays - $doy;

if ($doy == 0)
{
echo "Happy New Year!";
}
else
{
$newYear = $currentYear + 1;
echo "There are {$daysTil} days left until {$newYear}.";
}
?>

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.