CFLib.org – Common Function Library Project

DateTimeFormat(time [, dateFormat] [, timeFormat] [, joinStr])

Last updated November 26, 2001

Version: 1 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 4 time(s). Average Rating: 4.3

Description:
This function serves as a simple shorthand for calling both DateFormat and TimeFormat on one data object.

Return Values:
This function returns a string.

Example:

view plain print about
<CFOUTPUT>
Default: #DateTimeFormat(Now())#<BR>
Euro Date: #DateTimeFormat(Now(),"dd/mm/yy")#<BR>
With JoinStr = at: #DateTimeFormat(Now(),"mmmm d, yyyy","h:mm tt"," at ")#<BR>
With JoinStr = /: #DateTimeFormat(Now(),"mmmm d, yyyy","h:mm tt"," / ")#
</CFOUTPUT>

Parameters:

Name Description Required
time A data object. Yes
dateFormat The string to use to format dates. Defaults to No
timeFormat The string to use to format time. Defaults to No
joinStr This string is placed between the date and time. Defaults to one space character. No

Full UDF Source:

view plain print about
<cfscript>
/**
 * Calls both DateFormat and TimeFormat on a data object.
 * 
 * @param time      A data object. 
 * @param dateFormat      The string to use to format dates. Defaults to  
 * @param timeFormat      The string to use to format time. Defaults to  
 * @param joinStr      This string is placed between the date and time. Defaults to one space character. 
 * @return This function returns a string. 
 * @author Raymond Camden (ray@camdenfamily.com) 
 * @version 1, November 26, 2001 
 */

function DateTimeFormat(time) {
    var str = "";
    var dateFormat = "mmmm d, yyyy";
    var timeFormat = "h:mm tt";
    var joinStr = " ";
    
    if(ArrayLen(Arguments) gte 2) dateFormat = Arguments[2];
    if(ArrayLen(Arguments) gte 3) timeFormat = Arguments[3];
    if(ArrayLen(Arguments) gte 4) joinStr = Arguments[4];

    return DateFormat(time, dateFormat) & joinStr & TimeFormat(time, timeFormat);
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Adam Cameron Adam Cameron added
composeDateTime
19 day(s) ago

Chris Weller Chris Weller added
convertQueryStri...
a while ago

Greg Nettles Greg Nettles added
arrayDiff
a while ago

Nathan Dintenfass Nathan Dintenfass added
ArrayOfStructsSo...
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 36 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Rachel Lehman deAccent
Rated 5.0, 6 time(s)

Isaac Dealey                                      countArbitraryDa...
Rated 5.0, 5 time(s)

Created by Raymond Camden / Design by Justin Johnson