faqts : Computers : Programming : Languages : JavaScript : Language Core : Dates

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 6 people (67%) answered Yes
Recently 4 of 6 people (67%) answered Yes

Entry

How can I determine if Feb 29th occurs between two dates? i.e. 6/6/2021 - 9/6/2021

Jun 6th, 2003 10:11
jsWalter, A. McElwee,


1) check to see if month of first date is before or after feburary
2) if before, use the YEAR of that date
3) if after, use the YEAR of the second date
4) Now you can get a TRUE or FALSE (with method below) if
   the date we need to use is a Leap Year!
ex:  myDate.isLeapYear()
Walter
// ====================================================================
// Check to see if YEAR of given Date Object is a Leap Year
//   INPUT:  NONE - new method to Date Object
//   OUTPUT: TRUE or FALSE
//     by Unknown
//     modified by Walter Torres <jsWalter@torres.ws>
Date.prototype.isLeapYear         = _isLeapYear;
function _isLeapYear ()
{
     // Retreive YEAR
     var strYear  = this.getFullYear();
     return ( ( ( strYear % 4) == 0 ) && 
                ( ( ( strYear % 100 ) != 0 ) || 
                  ( ( strYear % 400 ) == 0 ) 
                )
            )
}    // _isLeapYear ( )
// ====================================================================