Jump to content

Php date functions


rshadarack

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.