User Guide

DateConvert 443
DateConvert
Description
Converts local time to Coordinated Universal Time (UTC), or UTC to local time. The function
uses the daylight savings settings in the executing computer to compute daylight savings time, if
required.
Returns
UTC- or local-formatted time object.
Category
Date and time functions
Function syntax
DateConvert("conversion-type", "date")
See also
GetTimeZoneInfo, CreateDateTime, DatePart
Parameters
Usage
When passing a date/time object as a string, you must enclose it in quotation marks. Otherwise, it
is interpreted as a numeric representation of a date/time object.
Note: You can pass the CreateDate or Now function as the date parameter of this function; for
example: #DateConvert(CreateDate(2001, 3, 3))#
Example
<h3>DateConvert Example</h3>
<!--- This shows conversion of current date - time to UTC and back. --->
<cfset curDate = Now()>
<p><cfoutput>The current date and time: #curDate#. </cfoutput></p>
<cfset utcDate = DateConvert("local2utc", curDate)>
<cfoutput>
<p>The current date and time converted to UTC time: #utcDate#.</p>
</cfoutput>
<!--- This code checks whether form was submitted. If so, the code generates
the CFML date with the CreateDateTime function. --->
<cfif IsDefined("FORM.submit")>
<cfset yourDate = CreateDateTime(FORM.year, FORM.month, FORM.day,
FORM.hour,FORM.minute, FORM.second)>
<p><cfoutput>Your date value, presented as a ColdFusion date/time
string:#yourdate#.</cfoutput></p>
<cfset yourUTC = DateConvert("local2utc", yourDate)>
<p><cfoutput>Your date and time value, converted to Coordinated Universal
Time
(UTC): #yourUTC#.</cfoutput></p>
Parameter Description
conversion-type local2Utc: Converts local time to UTC time.
utc2Local: Converts UTC time to local time.
date Date and time string or a variable that contains one.
To create, use
CreateDateTime.