Jump to content

Archived

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

rshadarack

Php date functions

Recommended Posts

I'm trying to use the php date functions, but not for the current year. For example, is there a function I could call to get if 1976 was a leap year? Or to find the first day (Monday, Tuesday, etc) of the year for 1996?

Share this post


Link to post
Share on other sites
For checking dates you could use checkdate() [a href=\"http://us3.php.net/manual/en/function.checkdate.php\" target=\"_blank\"]PHP:Manual[/a] and to see the day of the week you could use
[code]$date="1996-01-01";
$mynewdate =date("D j F y",strtotime($date));
echo $mynewdate;[/code]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.