ColdFusion Programming/dates

< ColdFusion Programming

Coldfusion can handle the creation, modification, display, and usage of dates.

Setting a Date

In order to set a date use the cfset function.

<cfset mydate = '12/3/2006'>

Displaying a Date

The basic display of a date is simply to output it.

<cfoutput>#mydate#</cfoutput>

This would display: 12/3/2006

There is function that allows you to easily convert a date into another format.

<cfoutput>#dateformat(mydate, 'yyyy/mm/dd')#</cfoutput>

This would display: 2006/12/3

The options to be used here are:

The options can be separated by - / , or space to create the format that you want.

Modifying a date

If we want to add 5 days to today we would use this function.

<cfset todayplus5 = dateadd('d', 5, now())> 

The options for dateadd are:

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.