Archive for July, 2009

Php code to find leap year or not

We can find a year is leap year or not in various ways.we can use the following fuctions in php.

  • By using date() function
  • By Modulus operator

Here is a sample php code that uses modulus(%)operator for finding the leap year.

Write the below code within php tags

[php]
<code>
<!–?PHP </p–> </code>

<code>$start = 1000;
$end = 1011;
for($i = $start; $i < $end; $i++)
{
if(($i%4) == 0){$val = "Leap Year";}else{$val = "Not Leap Year";}
echo $i, ‘ —> ‘.$val.”;
}</code>

?>
[/php]

It will produce the output as given below.

1000 —> Leap Year
1001 —> Not Leap Year
1002 —> Not Leap Year
1003 —> Not Leap Year
1004 —> Leap Year
1005 —> Not Leap Year
1006 —> Not Leap Year
1007 —> Not Leap Year
1008 —> Leap Year
1009 —> Not Leap Year
1010 —> Not Leap Year

You find leap years for any year ranges by changing the $start and $end.

Tags: ,

Tuesday, July 7th, 2009 PHP No Comments
Request a Free SEO Quote