How To Check Given Year Is Leap Year Or Not Using PHP

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

A leap year have 366 days in a year. A leap year comes after every four years. Hence a leap year is always a multiple of four.For example 2012, 2016, 2020, 2024, etc are leap years.So today to find it we use php script

How To Check Given Year Is Leap Year Or Not Using PHP

Complete Code For Checking Given Year Is Leap Year Or Not Using PHP.

<!DOCTYPE html>
<html>
<head>
    <title>How To Check Given Year Is Leap Year Or Not Using PHP</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;">Check Given Year Is Leap Year Or Not Using PHP</h1>
    </div>

    <div class="well">
        <form action="" method="post" >
            <label>Enter year</label><br>
            <input type="number" name="year"  value=""><br><br>
            <input type="submit" value="submit" class="btn btn-success" name="submit">
        </form>

        <?php
        if(isset($_POST['submit']))
        {
            //get the year
            $year = $_POST['year'];
            //multiple conditions to check the leap year
            if( (0 == $year % 4) and (0 != $year % 100) or (0 == $year % 400) )
            {
                echo "$year is a Leap Year";
            }
            else
            {
                echo "$year is not a Leap Year";
            }
        }
        ?>
    </div>
</div>
</body>
</html>

Related Post