GetElectionDay([TheYear])
Last updated August 28, 2001
Version: 1 | Requires: CF5 | Library: DateLib
Description:
Returns a date for US Presidential Election Day in a given year. Returns -1 for odd numbered years. If no year is specified, defaults to the current year.
Return Values:
Returns a date object.
Example:
<CFIF GetElectionDay() EQ -1>
There are no elections this year
<CFELSE>
<CFOUTPUT>
This year, Election Day is on #DateFormat(GetElectionDay(), 'dddd, mmm dd')#.
</CFOUTPUT>
</CFIF>
Parameters:
Name | Description | Required |
---|---|---|
TheYear | The year you want to return Election Day for. | No |
Full UDF Source:
/**
* Returns a date for Election Day in a given year
* This function requires the GetNthOccOfDayInMonth() function available from the DateLib library. Minor modifications by Rob Brooks-Bilson
*
* @param TheYear The year you want to return Election Day for.
* @return Returns a date object.
* @author Ken McCafferty (mccjdk@yahoo.com)
* @version 1, August 28, 2001
*/
//Election Day: Tuesday after First Monday in November, in even numbered years.
// for odd numbered years, -1 is returned
function GetElectionDay() {
Var TheYear=Year(Now());
if(ArrayLen(Arguments))
TheYear = Arguments[1];
if(TheYear MOD 2 eq 0){
return DateAdd("d",1,CreateDate(TheYear,11,GetNthOccOfDayInMonth(1,2,11,TheYear))); //add 1 day to first monday
}
else {
return -1;
}
}
Search CFLib.org
Latest Additions
Raymond Camden added
QueryDeleteRows
November 04, 2017
Leigh added
nullPad
May 11, 2016
Raymond Camden added
stripHTML
May 10, 2016
Kevin Cotton added
date2ExcelDate
May 05, 2016
Raymond Camden added
CapFirst
April 25, 2016