Jump to content

Recommended Posts

A year has to meet the following requirements to be a leap year:[list][*]It CANNOT be evenly divisible by 100[list][*]Exception: If the year is ALSO evenly divisible by 400, it is a leap year.[/list][*]It MUST be evenly divisible by 4[/list]This function takes care of the requirements.

[code]function isLeapYear($year)
{
    if( (($year % 100 != 0) && ($year % 4 == 0)) || ($year % 400 == 0))
    {
        $isLeapYear = true;
    }
    else
    {
        $isLeapYear = false;
    }
    return $isLeapYear;
}[/code]

Link to comment
https://forums.phpfreaks.com/topic/10148-php-date-functions/#findComment-37817
Share on other sites

  • 1 year later...
I don't quite get how it works... I've came to something like that. And now I'm thinking, how did I come up with this because 2000 / 4 = 500 and 2000 / 400 = 5, and none of them is "0".

So I came to this conclusion:

[code]
// Check if the entered year is a leapyear
if (!is_int($_POST['BoughtAtYear'] % 100) && (is_int($_POST['BoughtAtYear'] % 400) || is_int($_POST['BoughtAtYear'] % 4))){

  // In this case the year would be a leapyear

} else {

  // In this case the year would not be a leapyear

}

[/code]

Please tell me where I am wrong here :s

EDIT: Sorry I just saw how stupid I was. the "%" indicator gives the rest and not the value X_X
Link to comment
https://forums.phpfreaks.com/topic/10148-php-date-functions/#findComment-274822
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.