rshadarack Posted May 21, 2006 Share Posted May 21, 2006 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? Link to comment https://forums.phpfreaks.com/topic/10148-php-date-functions/ Share on other sites More sharing options...
Houdini Posted May 21, 2006 Share Posted May 21, 2006 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 https://forums.phpfreaks.com/topic/10148-php-date-functions/#findComment-37812 Share on other sites More sharing options...
neylitalo Posted May 21, 2006 Share Posted May 21, 2006 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 More sharing options...
Pastulio Posted June 14, 2007 Share Posted June 14, 2007 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 leapyearif (!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 :sEDIT: 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.