CreateDateTime

Description

Creates a date-time object.

Returns

A date/time value.

Category

Date and time functions

Function syntax

CreateDateTime(year, month, day, hour, minute, second, millisecond)

History

Introduced in ColdFusion MX6.

See also

CreateDateCreateTimeCreateODBCDateTimeNowEvaluation and type conversion issues in Data type conversion in the Developing ColdFusion Applications

Parameters

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

millisecond Integer in the range 0-999

In Adobe ColdFusion (2016 release), you can use the CreateDateTime function in the following ways:

  • CreateDateTime(year)
  • CreateDateTime(year, month)
  • CreateDateTime(year, month, day)
  • CreateDateTime(year, month, day, hour)
  • CreateDateTime(year, month, day, hour, minute)
  • CreateDateTime(year, month, day, hour, minute, second)
  • CreateDateTime(year, month, day, hour, minute, second, millisecond)

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'}

Example #2

<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'}

<cfscript>
  myVar = createDateTime(2022,9,15,1,32,59,999);
  writeOutput(myVar & "<br/>");
  writeOutput("From millisecond(DateTime)" & "<br/>")
  writeOutput(#millisecond(myVar)#);
  writeOutput("<br/>")
  writeOutput("From millisecond(DateTime)" & "<br/>")
  writeOutput(#myVar.millisecond()#);
</cfscript>

Output

{ts '2022-09-15 01:32:59'}
From millisecond(DateTime)
999
From millisecond(DateTime)
999

 Adobe

Pyydä apua nopeammin ja helpommin

Oletko uusi käyttäjä?

Adobe MAX 2024

Adobe MAX
Luovuuskonferenssi

14.–16.10. Miami Beach ja verkossa

Adobe MAX

Luovuuskonferenssi

14.–16.10. Miami Beach ja verkossa

Adobe MAX 2024

Adobe MAX
Luovuuskonferenssi

14.–16.10. Miami Beach ja verkossa

Adobe MAX

Luovuuskonferenssi

14.–16.10. Miami Beach ja verkossa