Speed up development with full-stack environments for every branch.

Learn More

How to find Leap Year [PHP and date]

317 Runs 4462 Views 694 Copies


dipesh.parmar 55

published 4 years ago

<div style="margin-left:50px;">
  <h2>Find Leap Year</h2>
    <strong>PHP Date:</strong> mktime could be used to find more specific things
    like find the next leap year in the calendar
    $day = "";
      since leap year falls ever 4 years so loop for 4 times 
    for($i=0; $i<4; $i++)
    	//get day timestamp for feburary 29 for this year
    	$day =  date("d", mktime(0, 0, 0, 2, 29, date("Y")+$i));	
    		check if day equals 29. 
    		If day is 29 then it must be the leap year. if day is 01, then it not a leap year.
    	if($day == 29)
    		$year = date("Y")+$i;
    echo "next leap year is in year $year";
    The mktime takes 6 arguments. The parameters are explained as below.

      <li>hour - The number of the hour.</li>
    	<li>minute - The number of the minute.</li>
    	<li>second - The number of seconds past the minute.</li>
    	<li>month - The number of the month.</li>
    	<li>day - The number of the day.</li>
    	<li>year - The number of year.</li>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).