Your Rating: Results: PatheticBadOKGoodOutstanding! 13 rates

Description

Formats date and time values using date and time formatting conventions.

Returns

A formatted date and time value.

History

ColdFusion 10: Added this function.

Syntax

dateTimeFormat (date)
dateTimeFormat (date [, mask])
dateTimeFormat (date [, mask, timeZone])

Properties

Parameter

Description

date

Required. A date/time object, in the range 100 AD-9999 AD.

mask

Optional. Characters that show how ColdFusion displays a date:

  •     d: Day of the month as digits; no leading zero for single-digit days.
  •     dd: Day of the month as digits; leading zero for single-digit days.
  •     EEE: Day of the week as a three-letter abbreviation.
  •     EEEE: Day of the week as its full name.
  •     m: Month as digits; no leading zero for single-digit months.
  •     mm: Month as digits; leading zero for single-digit months.
  •     mmm: Month as a three-letter abbreviation.
  •     mmmm: Month as its full name.
  •     yy: Year as last two digits; leading zero for years less than 10.
  •     yyyy: Year represented by four digits.
  •     G: Period/era string. (e.g. BC, AD)
  •     h: hours; no leading zero for single-digit hours (12-hour clock)
  •     hh: hours; leading zero for single-digit hours (12-hour clock)
  •     H: hours; no leading zero for single-digit hours (24-hour clock)
  •     HH: hours; leading zero for single-digit hours (24-hour clock)
  •     n: minutes; no leading zero for single-digit minutes
  •     nn: minutes; a leading zero for single-digit minutes
  •     s: seconds; no leading zero for single-digit seconds
  •     ss: seconds; leading zero for single-digit seconds
  •     l or L: milliseconds, with no leading zeros
  •     t: one-character time marker string, such as A or P
  •     tt: multiple-character time marker string, such as AM or PM

The following masks tell how to format the full date and time and cannot be combined with other masks:

  • short: equivalent to m/d/y h:nn tt
  • medium: equivalent to mmm d, yyyy h:mm:ss tt
  • long: medium with full month name rather than abbreviation, followed by three-letter time zone; as in, mmmm d, yyyy h:mm:ss tt EST
  • full: equivalent to EEEE, mmmm d, yyyy h:mm:ss tt EST
The function also follows Java date time mask. For details, see the section Date and Time Patterns on this page.

timeZone

The time-zone information. You can specify in either of the following formats:

  • Abbreviation such as GMT or PST
  • Full name such as Europe/Dublin
    By default, this is the time-zone followed by the system.

Example

Labels
  • None
  1. Feb 24, 2014

    The values given for the mask attribute do not match the values used in the examples and do not match the linked Java date time mask.

    For example, when trying to output the name of day of the week (Monday, Tuesday) the mask suggests using 'dddd' whereas the linked documentation says to use 'EEEE'.

    Using dddd results in 0025 (on 25th Feb) whereas EEEE results in Tuesday (which is correct.)

    TLDR use the linked Java date time masks in preference to the details on this page.

     

  2. Apr 01, 2014

    In the mask parameter description for bullet points short, medium, long and full, the mask has "mm" for seconds which should read "nn".

    Example:

    short: equivalent to m/d/y h:mm tt

    Should be:

    hort: equivalent to m/d/y h:nn tt

  3. Sep 16, 2014

    In addition to the masking issues that others have mentioned, it seems that "DD" (upper case) prints the day-of-year (such that on Feb 1st, the printed value is 32). This is not mentioned in the masks on this page.

    This page needs a serious cleaning up.

  4. Oct 10, 2014

    The example:

    <li>#DateTimeFormat(todayDateTime, "yyyy.MM.dd G 'at' HH:nn:ss z")#

    produces 2014.10.10 AD 'A' 11:12:35 BST for me - not really what I was expecting. Can't I escape a string?

  5. Oct 15, 2014

    I've updated all of the masks and incorporated all of the feedback from comments thus far. Thanks for taking an interest in your own documentation, Adobe. </snark>

    leo ponton: You can include additional text in your mask as long as it doesn't include mask characters; but as far as I know there's no way to escape them. For example, you could use "@" and it should print the "@" character in that position.


Searching ColdFusion, English documentation