CFLib.org – Common Function Library Project

dayOfWeekAsInteger(day)

Last updated December 09, 2013

author

Simon Bingham

Version: 1 | Requires: CF9 | Library: DateLib

Description:
Converts a day string to a number (e.g. Sunday to 1, Monday to 2, etc.).

Return Values:
A numeric index corresponding to the day of the week (Sunday=1)

Example:

<cfoutput>#dayOfWeekAsInteger("Wednesday")#</cfoutput>

Parameters:

Name Description Required
day A day of the week in English, eg Wednesday Yes

Full UDF Source:

/**
 * Converts a day string to a number.
 * v0.9 by Simon Bingham
 * v1.0 by Adam Cameron. Rename &amp; raise exception when input is invalid
 * 
 * @param day      A day of the week in English, eg Wednesday (Required)
 * @return A numeric index corresponding to the day of the week (Sunday=1) 
 * @author Simon Bingham (me@simonbingham.me.uk) 
 * @version 1, December 9, 2013 
 */
numeric function dayOfWeekAsInteger(required string day){
    var days = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
    var index = listFindNoCase(days, day);
    if (index){
        return index;
    }else{
        throw(type="ArgumentOutOfRangeException", message="Invalid day value", detail="day argument value must be one of #days#");
    }
}

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

Created by Raymond Camden / Design by Justin Johnson