CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

UnitsDate

nth Week Day

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 4.68
sub units 6.50
add a commercial licence to your cart
0
viewed 2344 times and licensed 68 times

Returns the date of the nth weekday within the specified month and year.

Further Info Controller: CodeCogs  Contact Controller
+View version details
Contents hide toc
buy now     get GPL     add to cart

Interface

#include <codecogs/units/date/nthweekday.h>

using namespace Units::Date;

int nthWeekDay (int Nth, int WeekDay, int Year, int Month, int Type=1)
Returns the date of the nth weekday within the specified month and year.
ExcelInteger cc_nthWeekDay (Integer Nth, Integer WeekDay, Integer Year, Integer Month, Integer Type)
This function is available as a Microsoft Excel add-in.

Function Documentation

Nth Week Day Calculator
  
Add calculator to website or email
 
intnthWeekDayintNth
intWeekDay
intYear
intMonth
intType = 1 )
Calculates the date of the nth occurance of a particular weekday (Sunday to Saturday) within a specified month and year. Many public holidays and other events (see also summerTime) are performed on specific days of the week; very often the first or last occurance of that day within the month. This function uses weekdays within the Gregorian calendar to return the serial Julian date (number of days since 24 November 4714BC).

For example, US events include:

UK holidays include:
Example 1:
To compute the UK holidays:
#include <stdio.h>
#include <codecogs/units/date/nthweekday.h>
#include <codecogs/units/date/dateymd.h>
#include <codecogs/units/date/month_str.h>
using namespace Units::Date;
 
int main()
{
  int d,m,y;
  for(int i=2004; i<=2006; i++)
  {
    printf("\nIn %d:",i);
    dateYMD(nthWeekDay(1, Monday, i, May), y,m,d);        // First Monday
    printf("\n   May Day Bank Holiday is on: %2d %s",d,month_str(m));

dateYMD(nthWeekDay(0, Monday, i, May), y,m,d); // last Monday printf("\n Spring Bank Holiday is on: %2d %s",d,month_str(m));

dateYMD(nthWeekDay(0, Monday, i, August), y,m,d); // last Monday printf("\n Late Summer Holiday is on: %2d %s",d,month_str(m)); } return 0; }
Output:
In 2004:
May Day Bank Holiday is on:  3 May
Spring Bank Holiday is on:  31 May
Late Summer Holiday is on:  30 August
In 2005:
May Day Bank Holiday is on:  2 May
Spring Bank Holiday is on:  30 May
Late Summer Holiday is on:  29 August
In 2006:
May Day Bank Holiday is on:  1 May
Spring Bank Holiday is on:  29 May
Late Summer Holiday is on:  28 August

Parameters:
Nthidentifies which WeekDay from the start of the month to obtain (e.g. the 1st Friday, 3rd Monday). A zero value will return the date of the last WeekDay, with negative values returning earlier weekdays from the end of the month.
WeekDayis the day of the week required, with its value depending upon the Type (see below).
Yearcan be any integer greater than 4800 BC (-4799).
Monthcontains the month of the year. This value must be within the range -9 to 14 (inclusive), though value outside the range 1-12 will be divided by by 12, such that the Year incremented by the quotient and the Month set to the remainder.
Typedefines the input form for the WeekDay:
Authors:
Will Bateman
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 18 Oct 07 @ 17:07     Page Rendered: 2010-03-12 04:17:47

Valid CSS!   Valid XHTML 1.0 Transitional