CFLib.org – Common Function Library Project

dayOfWeekAsInteger(day)

Last updated December 9, 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#");
    }
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson