Determine Day of Week for a Date

From HotDocs Wiki

Jump to: navigation, search

Sometimes, it is necessary to determine which day of the week a given date falls on. For example, if a payment due date falls on a Saturday or Sunday, you may want to determine the date of the following Monday.

Example

The following computation determines the day of the week for a date, and then adds one or two days, if necessary, to return the date of the following Monday.

In the following example, "Date Var" is any Date variable. In this example, it can be a payment due date:

IF DAY OF WEEK( Date Var ) = 7
  Date Var + 2 DAYS 
ELSE IF DAY OF WEEK( Date Var ) = 1
  Date Var + 1 DAYS 
ELSE 
  Date Var 
END IF  Date Var

Note: The DAY OF WEEK expression returns the day of the week as an integer. Sunday has a value of 1, Monday has a value of 2, and so forth.