Jump to content


Photo

Php date functions


  • Please log in to reply
3 replies to this topic

#1 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 21 May 2006 - 11:16 PM

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?

#2 Houdini

Houdini
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 21 May 2006 - 11:35 PM

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
$date="1996-01-01";
$mynewdate =date("D j F y",strtotime($date));
echo $mynewdate;

We the unwilling, led by the unknowing,
have done so much, for so long, with so little,
that we are now quqlified to do anything, with nothing!

#3 neylitalo

neylitalo
  • Staff Alumni
  • Advanced Member
  • 1,854 posts
  • LocationMichigan, USA

Posted 21 May 2006 - 11:51 PM

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

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



http://nealylitalo.net - My personal website, and home of The Netizen's Journal.

#4 Pastulio

Pastulio
  • Members
  • PipPipPip
  • Advanced Member
  • 85 posts

Posted 14 June 2007 - 07:20 PM

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:

// 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
			
}


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users