Jump to content

Php date functions


rshadarack

Recommended Posts

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]
Link to comment
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]

Link to comment
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
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.