Parameter
Creates a date-time object.
A date/time value.
CreateDateTime(year, month, day, hour, minute, second)
Introduced in ColdFusion MX6.
CreateDate, CreateTime, CreateODBCDateTime, Now; Evaluation and type conversion issues in Data type conversion in the Developing ColdFusion Applications
Parameter |
Description |
|---|---|
year |
Integer in the range 0-9999. Integers in the range 0-29 are converted to 2000-2029. Integers in the range 30-99 are converted to 1930-1999. You cannot specify dates before AD 100. |
month |
Integer in the range 1 (January) - 12 (December) |
day |
Integer in the range 1 - 31 |
hour |
Integer in the range 0 - 23 |
minute |
Integer in the range 0 - 59 |
second |
Integer in the range 0 - 59 |
In Adobe ColdFusion (2016 release), you can use the CreateDateTime function in the following ways:
|
Parameter |
Default value |
|
Month |
1 |
|
Day |
1 |
|
Hour |
0 |
|
Minute |
0 |
|
Second |
0 |
If you pass the parameter values only partially, other fields take the default value. For example, CreateDateTime(2016) produces '2016-01-01 00:00:00', where 2016 is the specified parameter and the rest are produced by default.
Example #1
<cfscript>
// Create date time object and display it
WriteOutput(CreateDateTime(2016,2,16,16,45,34) & " | "); // Create object for specified time
WriteOutput(#now()#); // Create object for now()
</cfscript>
Output
{ts '2016-02-16 16:45:34'} | {ts '2016-03-14 13:15:31'}
<cfscript>
// In ColdFusion (2016 release), you can use the CreateDateTime in the following ways
WriteOutput(CreateDateTime(2016) & " | ");
WriteOutput(CreateDateTime(2016,6) & " | ");
WriteOutput(CreateDateTime(2016,6,10) & " | ");
WriteOutput(CreateDateTime(2016,6,10,17) & " | ");
WriteOutput(CreateDateTime(2016,6,10,17,45) & " | ");
WriteOutput(CreateDateTime(2016,6,10,17,45,38));
</cfscript>
Output
{ts '2016-01-01 00:00:00'} | {ts '2016-06-01 00:00:00'} | {ts '2016-06-10 00:00:00'} | {ts '2016-06-10 17:00:00'} | {ts '2016-06-10 17:45:00'} | {ts '2016-06-10 17:45:38'}
<cfscript>
year = 2018;
month = 11;
day = 02;
hour = 1;
minute= 09;
second= 46;
myDate=CreateDateTime(year,month,day,hour,minute,second)
writeOutput("The date and time is: " & myDate);
</cfscript>
Output
The date and time is: {ts '2018-11-02 01:09:46'}
Sign in to your account