View comments | RSS feed

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)

See also

CreateDate, CreateTime, CreateODBCDateTime, Now; Date-time functions and queries when ODBC is not supported in Using ColdFusion Variables in ColdFusion MX 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

hour

Integer in the range 0-23

minute

Integer in the range 0-59

second

Integer in the range 0-59

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>Formatted with CreateDateTime: #CreateDateTime(form.year, form.month,
form.day, form.hour, form.minute, form.second)
# <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,
form.hour, form.minute, form.second)
)# <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="createdatetime.cfm" METHOD="POST"> <p>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> <p><INPUT TYPE="Submit" NAME=""> <INPUT TYPE="RESET"> </cfform>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


WebPexDev said on Nov 5, 2007 at 12:56 PM :
CreateDateTime() does not return the correct result for CreateDateTime(2006,4,2,2,0,0). This is the start date of Daylight Saving Time in the US. It returns {2006-04-2 3:00:00} when it should return {2006-04-2 2:00:00}. It is assuming the time you want to create is a US time which observes DST. In my case I'm trying to create a time in GMT for {2006-04-2 2:00:00}. If you use CreateDateTime(2006,4,2,3,0,0) you also get
{2006-04-2 3:00:00}. I assume this will also be incorrect for the DST end date of 2006-10-29. Also, because DST has changed for 2007 going forward it's pretty much useless.
halL said on Nov 9, 2007 at 2:20 PM :
This has been fixed In ColdFusion 8.
CreateDateTime(2006,4,2,2,0,0) results in an invalid date value error.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000423.htm