Dates/Times

This category focuses on working with dates and times in ColdFusion. Common problems faced by developers, such as printing dates and times in different ways, determining the difference between two dates, and dealing with dates/times in non-English locales are all explored in detail.

Problems

How do I check if a date is in the current century?
Date comparisons are fairly easy in ColdFusion. One common task is to compare a date value to the cu...

How do I format an Active Directory Timestamp?
Time in Active Directory is stored in a 64 bit integer that keeps track of the number of 100-Nanose...

How do I retrieve the dates for specific days of the week for all months in a year, and put them into an array?
While there is no ColdFusion specific function to return this, it is possible to build such function...

How do you determine the beginning of a given week?
When building online calendars it's often useful to know the first day of the week for a given date...

You have a date and time in Epoch seconds that you would like to convert to a date/time object.
Use DateAdd() to add the Epoch seconds to the Epoch date. ColdFusion does not natively deal with ...

You have a date, time, or both and you need to convert it to Epoch seconds.
Use the DateDiff() function to do the conversion. If you are converting from local time, you'll fir...

You have a string, such as user input, that you need to convert to a date/time object.
The ParseDateTime() function, and its locale specific sibling LSParseDateTime() can be used to conve...

You have two dates/times you want to compare.
You have two dates/times you want to compare. Use one of ColdFusion's comparison operators in an ...

You need to create a date/time object.
You can write the date/time value as a string, or use the CreateDate(), CreateTime(), CreateDateTime...

You need to determine the difference between two dates or times.
Use DateDiff() to return the interval between two dates and/or times. The DateDiff() function is us...

You need to determine whether a string or numeric value is a valid date object.
Use IsDate() or LSIsDate() for strings, or IsNumericDate() for numeric values. The IsDate() functio...

You need to extract the day/month/year/hour/minute/second (DMYHMS), day of the week/year, week number, or quarter from a date/time object.
DatePart() accepts two parameters, the datepart you want to extract, and the date you want to extrac...

You need to format a date/time object.
To format a date for the English (US) locale, use the DateFormat() function. For times using the U....

You need to get the current date/time from the server.
The Now() function can be used to obtain the current date/time from the ColdFusion server: The ...

You want to add to or subtract from a date/time object.
The DateAdd() function can be used to add or subtract various units of time from a date/time object....