noname_clark Posted October 5, 2008 Share Posted October 5, 2008 so i am creating this calendar for my website, and i need to know if I can figure out if it a leap year for a specific year. so for example, the url is: calendar.php?month=February&year=2008 how can i have it so that when it goes to that page, it knows if it is a leap year based on the 'year' variable in the query string? or maybe enen a little simpler example: how can i have the page know if calendar.php?month=February&year=2008 is a leap year calendar verses calendar.php?month=February&year=2020 ??? any help would be great. thanks. Link to comment https://forums.phpfreaks.com/topic/127085-solved-timedate-stamp-and-leap-year/ Share on other sites More sharing options...
genericnumber1 Posted October 5, 2008 Share Posted October 5, 2008 $time = strtotime('1/1/2008'); echo date('L', $time); 1 for leap year, 0 for not. Much easier than doing the math yourself there are so many weird rules for whether something is a leap year or not. edit: woops, forgot the day/month. should work fine now. meh, why not add the actual algorithm? <?php function isLeapYear($year) { return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)); } ?> use that if for some reason you have a problem with the date() one. Link to comment https://forums.phpfreaks.com/topic/127085-solved-timedate-stamp-and-leap-year/#findComment-657378 Share on other sites More sharing options...
noname_clark Posted October 5, 2008 Author Share Posted October 5, 2008 thanks for replying =) so i tried the: $time = strtotime('1/1/2008'); echo date('L', $time); but i had to put $year in for '2008' so that i could change the year based on which year the user wanted to see, so i tried this: $time = strtotime('1/1/$year'); echo date('L', $time); now the value of $time is -1 where if it was left at '2008' i get 1199163600 so how do i pass the varable $year using strtotime? or, using the algorithm how does it work so i can try that? (sorry, i dont know much about functions in php) Link to comment https://forums.phpfreaks.com/topic/127085-solved-timedate-stamp-and-leap-year/#findComment-657386 Share on other sites More sharing options...
genericnumber1 Posted October 5, 2008 Share Posted October 5, 2008 in php if you use single quotes it doesn't parse for variables so you'd need to do "1/1/$year" or '1/1/'.$year As for the function you would call it isLeapYear($year); it makes sure the year is divisible by 4, but not by 100 unless it is divisible by 400. Link to comment https://forums.phpfreaks.com/topic/127085-solved-timedate-stamp-and-leap-year/#findComment-657387 Share on other sites More sharing options...
noname_clark Posted October 5, 2008 Author Share Posted October 5, 2008 thank you so much! i have been working on this for hours and now it works! lol Link to comment https://forums.phpfreaks.com/topic/127085-solved-timedate-stamp-and-leap-year/#findComment-657389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.