Displaying the current date and time in different ways

Using the DateFormat() function and/or the TimeFormat() function you can display the date and time in different ways using a mask:

The Now() function returns the current date and time from the server.

<cfoutput>#Now()#</cfoutput>

Returns: {ts '2003-08-25 19:06:12'}

Using the ColdFusion DateFormat() function, we can change the output.

<cfoutput>#DateFormat(Now())#</cfoutput>

25-Aug-03

We can mask the output to be more specifying.

<cfoutput>#DateFormat(Now(),"mm-dd-yy")#</cfoutput>

08-25-03

Here are some examples:

Mask: ddd, mm d, yyyy

Returns: Mon, 08 25, 2003

Mask: dddd, mmmm d, yyyy

Returns: Monday, August 25, 2003

Mask: dddd, mmmm, yyyy

Returns: Monday, August, 2003

Mask: mmmm, yyyy

Returns: August, 2003

The TimeFormat() function is similar to DateFormat, except it returns the time.

<cfoutput>#TimeFormat(Now())#</cfoutput>

07:06 PM

Examples:

mask: hh:mm:ss tt

Returns: 07:06:12 PM

Notice: If we change the hh to capital letters HH, we will get a 24-hour clock.

mask: HH:mm:ss

Returns: 19:06:12

Advertisement

No User Comments.

No User Comments, be the first one to write your comments?

ApplayIT is owned by Scandic Systems LTD [UK] Company No. 5984000. All other trademarks and copyrights are the property of their respective holders.