phpQuestioner Posted April 20, 2007 Share Posted April 20, 2007 I am using this function below in a script to create a count down script. <? date(("z"), time() - (14400 * 1)) ?> My question is; does the "z" (0 - 365) go up to a maxium of 366 when it is leap year? Quote Link to comment https://forums.phpfreaks.com/topic/47963-solved-date-with-leap-year-question/ Share on other sites More sharing options...
dustinnoe Posted April 20, 2007 Share Posted April 20, 2007 <?php // leap year to test $time = strtotime("Dec 31, 2004"); $julian = date('z', $time); echo $julian; ?> This will output '365' but Jan 1st will output '0' so the answer to your question is yes and no at the same time. Quote Link to comment https://forums.phpfreaks.com/topic/47963-solved-date-with-leap-year-question/#findComment-234371 Share on other sites More sharing options...
phpQuestioner Posted April 21, 2007 Author Share Posted April 21, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/47963-solved-date-with-leap-year-question/#findComment-234400 Share on other sites More sharing options...
kenrbnsn Posted April 21, 2007 Share Posted April 21, 2007 Just check the day number for the last day of the year. It will be 365 for leap years and 364 for non-leap years. Ken Quote Link to comment https://forums.phpfreaks.com/topic/47963-solved-date-with-leap-year-question/#findComment-234409 Share on other sites More sharing options...
phpQuestioner Posted April 21, 2007 Author Share Posted April 21, 2007 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."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/47963-solved-date-with-leap-year-question/#findComment-234440 Share on other sites More sharing options...
dustinnoe Posted April 21, 2007 Share Posted April 21, 2007 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}."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/47963-solved-date-with-leap-year-question/#findComment-234521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.