CreateDate(year, month, day)
CreateDateTime,
CreateODBCDate
Parameter | Description |
---|---|
year |
Integer, in the range 0-9999. See "How ColdFusion processes two-digit year values". |
month |
Number in the range 1 (January) - 12 (December) |
day |
Number in the range 1 - 31 |
CreateDate
is a subset of CreateDateTime.
The time in the returned object is set to 00:00:00.
For most locales, if the year part of a date string uses the abbreviated pattern "y" or "yy", it is interpreted relative to a century, by adjusting dates to within 80 years before and 20 years after the date instance is created.
For example, if the pattern is "mm/dd/yy", and a date instance is created on Jan 1, 1997, the string "01/11/12" is interpreted as Jan 11, 2012. The string "05/04/64" is interpreted as May 4, 1964.
For the following locales, the algorithm is similar, but the adjustment is made to within 72 years before and 28 years after the date instance is created:
This applies to the Sun JRE Version 1.4 and the IBM JRE Version 1.3.0.
<h3>CreateDate Example</h3> <CFIF IsDefined("form.year")> <p>Your date value, generated with CreateDate: <CFSET yourDate = CreateDate(form.year, form.month, form.day)> <cfoutput> <ul> <li>Formatted with CreateDate: #CreateDate(form.year, form.month, form.day)# <li>Formatted with CreateDateTime: #CreateDateTime(form.year, form.month, form.day, 12,13,0)# <li>Formatted with CreateODBCDate: #CreateODBCDate(yourDate)# <li>Formatted with CreateODBCDateTime: #CreateODBCDateTime(yourDate)# </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>Formatted with CreateDateTime and dateFormat: #DateFormat(CreateDateTime(form.year, form.month, form.day, 12,13,0))# <li>Formatted with CreateODBCDate and dateFormat: #DateFormat(CreateODBCDate(yourDate), "mmmm d, yyyy")# <li>Formatted with CreateODBCDateTime and dateFormat: #DateFormat(CreateODBCDateTime(yourDate), "d/m/yy")# </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>