– Common Function Library Project

composeDateTime([date][, year][, month][, day][, hour][, minute][, second])

Last updated May 03, 2013


Adam Cameron

Version: 1 | Requires: CF9 | Library: DateLib

Similar to createDateTime(), except all arguments are optional so one can be selective in which parts to specify for the result. Any unspecified arguments default to the current datetime's relevant component. This is really just a patch for a shortcoming in CFML's createDateTime() function. If you use this, perhaps vote to get an "official" version added to CFML:

Return Values:
A date


defaultsWereSet = composeDateTime();
justYearWasSet = composeDateTime(2011);
monthWasSetToo = composeDateTime(2011, 3);
dayWasSetToo = composeDateTime(2011, 3, 24);
hourWasSetToo = composeDateTime(2011, 3, 24, 9);
minWasSetToo = composeDateTime(2011, 3, 24, 9, 30);
secWasSetToo = composeDateTime(2011, 3, 24, 9, 30, 00);


Name Description Required
date The base date to start with. Defaults to now() No
year The year to set No
month The month to set No
day The day to set No
hour The hour to set No
minute The minute to set No
second The second to set No

Full UDF Source:

 * Creates a date time from optional date parts
 * v1.0 by Adam Cameron
 * v1.1 by Adam Cameron (under guidance of GrumpyCFer). Adding date argument to allow for dates to not necessarily be now()-based. Fixed potential temporal issue.
 * @param date      The base date to start with. Defaults to now() (Optional)
 * @param year      The year to set (Optional)
 * @param month      The month to set (Optional)
 * @param day      The day to set (Optional)
 * @param hour      The hour to set (Optional)
 * @param minute      The minute to set (Optional)
 * @param second      The second to set (Optional)
 * @return A date 
 * @author Adam Cameron ( 
 * @version 1, May 3, 2013 
private date function composeDateTime(date date=now(), numeric year, numeric month, numeric day, numeric hour, numeric minute, numeric second){
    param name="arguments.year" default=year(date);
    param name="arguments.month" default=month(date);
    param name="" default=day(date);
    param name="arguments.hour" default=hour(date);
    param name="arguments.minute" default=minute(date);
    param name="arguments.second" default=second(date);

    return createDateTime(arguments.year, arguments.month,, arguments.hour, arguments.minute, arguments.second);


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson