CFLib.org – Common Function Library Project

getMeridiem(dateTime)

Last updated November 14, 2012

author

Nolan Erck

Version: 1 | Requires: CF9 | Library: DateLib

Description:
Returns the "am/pm" portion of a time/date (aka the "meridiem"). Works with both dates created via plain text (i.e. "4/1/2012") and via CreateDateTime(), etc. This is basically a wrapper around the call to TimeFormat() to both a) add some extra validation for dealing with potentially badly formatted dates and b) uses the proper "meridiem" name for this portion of the timestamp, adding some readability to the code.

Return Values:
Returns a string that is either AM or PM

Example:

// example with date/times showing the cut-over from AM to PM
baseTS = createDateTime(year(now()), month(now()), day(now()), 11, 59, 55);
for (i=0; i <= 10; i++){
	testTs = dateAdd("s", i, baseTs);
	writeOutput("#testTs#: #getMeridiem(testTs)#<br />");
}

Parameters:

Name Description Required
dateTime A datetime as a date or a string that will parse as a datetime Yes

Full UDF Source:

/**
 * I return the &quot;am/pm&quot; portion of a date/time (aka the &quot;meridiem&quot;).
 * * version 0.1 by Nolan Erck
 * * version 0.2 by Nolan Erck: fixing small bug
 * * version 1.0 by Adam Cameron: factoring-out redundant date-checking logic
 * 
 * @param dateTime 	 A datetime as a date or a string that will parse as a datetime (Required)
 * @return Returns a string that is either AM or PM 
 * @author Nolan Erck (nolan@southofshasta.com) 
 * @version 1.1, November 14, 2012 
 */
string function getMeridiem(required date dateTime){
	return timeFormat(dateTime, "tt");
}
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