Adobe ColdFusion 8

CreateDate

Description

Creates a date/time object.

Returns

A date/time value.

Category

Date and time functions

Function syntax

CreateDate(year, month, day)

See also

CreateDateTime, CreateODBCDate; "Date-time functions and queries when ODBC is not supported" in the ColdFusion Developer's Guide

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

Usage

CreateDate is a subset of CreateDateTime.

The time in the returned object is set to 00:00:00.

Example

<h3>CreateDate Example</h3>
<cfif IsDefined("form.year")>
<p>Your date value, generated with CreateDate:</p>
<cfset yourDate = CreateDate(form.year, form.month, form.day)>
<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, 12,13,0)#</li>
    <li>Formatted with CreateODBCDate: #CreateODBCDate(yourDate)#</li>
    <li>Formatted with CreateODBCDateTime: #CreateODBCDateTime(yourDate)#</li>
</ul>

<p>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, 12,13,0))#</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="createdate.cfm" METHOD="POST">
<p>Enter the year, month and day, as integers:
<pre>
Year<cfinput type="Text" name="year" value="1998" validate="integer" required="Yes">
Month<cfinput type="Text" name="month" value="6" validate="integer" required="Yes">
Day<cfinput type="Text" name="day" value="8" validate="integer" required="Yes">
</pre>
<p><input type="Submit" name=""> <input type="RESET">
</cfform>