What is Leap Year ?
A Year, occurred once every four years, which has 366 days , one additional day ( 29 February ) added to keep the calendar year synchronised with the astronomical or seasonal year.
Programs Functions
//Method 1 function leapyear_1($year) { // conditions to find out the leap year return (0 == $year % 4) ? true : false; } //Method 2 function leapyear_2($year) { // conditions to find out the leap year if ((0 == $year % 4) && (0 != $year % 100) || (0 == $year % 400)) { return true; } else { return false; } } //Method 3 function leapyear_3($year) { // conditions to find out the leap year return (date('L', mktime(0, 0, 0, 1, 1, $year))) ? true : false; } //Method 4 function leapyear_4($year) { // conditions to find out the leap year return checkdate(2, 29, $year); } //Method 5 function leapyear_5($year) { // conditions to find out the leap year $leap = date('L', mktime(0, 0, 0, 1, 1, $year)); return $year.' '.($leap ? 'is' : 'is not').' a leap year.'; }
Method 1
//Method 1 function leapyear_1($year) { // conditions to find out the leap year return (0 == $year % 4) ? true : false; } $year = 2020; if (leapyear_1($year)) { echo "$year is a Leap Year"; } else { echo "$year is Not a Leap Year"; } //2020 is a Leap Year
Method 2
//Method 2 function leapyear_2($year) { // conditions to find out the leap year if ((0 == $year % 4) && (0 != $year % 100) || (0 == $year % 400)) { return true; } else { return false; } } $year = 2020; if (leapyear_2($year)) { echo "$year is a Leap Year"; } else { echo "$year is Not a Leap Year"; } //2020 is a Leap Year
Method 3
//Method 3 function leapyear_3($year) { // conditions to find out the leap year return (date('L', mktime(0, 0, 0, 1, 1, $year))) ? true : false; } $year = 2020; if (leapyear_3($year)) { echo "$year is a Leap Year"; } else { echo "$year is Not a Leap Year"; } //2020 is a Leap Year
Method 4
//Method 4 function leapyear_4($year) { // conditions to find out the leap year return checkdate(2, 29, $year); } $year = 2020; if (leapyear_4($year)) { echo "$year is a Leap Year"; } else { echo "$year is Not a Leap Year"; } //2020 is a Leap Year
Method 5
//Method 5 function leapyear_5($year) { // conditions to find out the leap year $leap = date('L', mktime(0, 0, 0, 1, 1, $year)); return $year.' '.($leap ? 'is' : 'is not').' a leap year.'; } echo leapyear_5(2020); //2020 is a leap year.
(Visited 316 times, 1 visits today)
Written by: