createDateTime

Description

Creates a date-time object.

Categories

Related

Syntax

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

Attributes

AttributeDescriptionRequiredDefault
dayInteger in the range 1–31
hourInteger in the range 0–23
minuteInteger in the range 0–59
monthInteger in the range 1 (January)–12 (December)
secondInteger in the range 0–59
yearInteger 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.

Returns

A date/time value.

Example

<h3>CreateDateTime Example</h3> 
 
<cfif IsDefined("form.year")> 
Your date value, generated with CreateDateTime: 
<cfset yourDate = CreateDateTime(form.year, form.month, form.day, 
    form.hour, form.minute, form.second)> 
 
<cfoutput> 
<ul> 
    <li>Formatted with CreateDate: #CreateDate(form.year, form.month, form.day)#</li> 
    <li>Formatted with CreateDateTime: #CreateDateTime(form.year, form.month, 
    form.day, form.hour, form.minute, form.second)#</li> 
    <li>Formatted with CreateODBCDate: #CreateODBCDate(yourDate)#</li> 
    <li>Formatted with CreateODBCDateTime: #CreateODBCDateTime(yourDate)#</li> 
</ul> 
 
The same value can be formatted with DateFormat: 
<ul> 
    <li>Formatted with CreateDate and DateFormat:  
        #DateFormat(CreateDate(form.year, form.month, form.day), "mmm-dd-yyyy")#</li> 
    <li>Formatted with CreateDateTime and DateFormat:  
        #DateFormat(CreateDateTime(form.year, form.month, form.day, 
    form.hour, form.minute, form.second))#</li> 
    <li>Formatted with CreateODBCDate and DateFormat:  
        #DateFormat(CreateODBCDate(yourDate), "mmmm d, yyyy")#</li> 
    <li>Formatted with CreateODBCDateTime and DateFormat:  
        #DateFormat(CreateODBCDateTime(yourDate), "d/m/yy")#</li> 
</ul> 
</cfoutput> 
</cfif> 
 
<CFFORM ACTION="createdatetime.cfm" METHOD="POST"> 
Please enter the year, month, and day, in integer format, for a date to view: 
<PRE> 
Year    <CFINPUT TYPE="Text" NAME="year" VALUE="1998" VALIDATE="integer"  
        REQUIRED="Yes"> 
Month    <CFINPUT TYPE="Text" NAME="month" VALUE="6" RANGE="1,12"  
        MESSAGE="Please enter a month (1-12)" VALIDATE="integer"  
        REQUIRED="Yes"> 
Day    <CFINPUT TYPE="Text" NAME="day" VALUE="8" RANGE="1,31"  
        MESSAGE="Please enter a day of the month (1-31)" VALIDATE="integer"  
        REQUIRED="Yes"> 
Hour    <CFINPUT TYPE="Text" NAME="hour" VALUE="16" RANGE="0,23"  
        MESSAGE="You must enter an hour (0-23)" VALIDATE="integer"  
        REQUIRED="Yes"> 
Minute    <CFINPUT TYPE="Text" NAME="minute" VALUE="12" RANGE="0,59"  
        MESSAGE="You must enter a minute value (0-59)" VALIDATE="integer"  
        REQUIRED="Yes"> 
Second    <CFINPUT TYPE="Text" NAME="second" VALUE="0" RANGE="0,59"  
        MESSAGE="You must enter a value for seconds (0-59)" VALIDATE="integer"  
        REQUIRED="Yes"> 
</PRE> 
<INPUT TYPE="Submit" NAME=""> <INPUT TYPE="RESET"> 
</cfform>