Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
I am the chief technical officer at InVision App, Inc - a prototyping and collaboration platform for designers, built by designers. I also rock out in JavaScript and ColdFusion 24x7.
Meanwhile on Twitter
Loading latest tweet...
Ben Nadel at NCDevCon 2011 (Raleigh, NC) with:

Hours And Seconds Work In ColdFusion DateFormat()

By Ben Nadel on
Tags: ColdFusion

This is probably the most useless piece of information, but I accidentally discovered that the hours (h) and seconds (s) masks work in ColdFusion's DateFormat() method. Yesterday, I was trying to format a time stamp but absent mindedly used the DateFormat() instead of the TimeFormat() method. To my surprise, it actually worked (at least partially). Running this code several times:

  • #DateFormat( Now(), "hh ss" )#

... gives me:

08 28
08 31
08 35
08 40

I am running this a 8:07 AM and as you can see, even though we are using ColdFusion's DateFormat() method, the hours comes out correctly (8) and the seconds are incrementing as refresh the page.

This is very strange to me. Applying a mask must take processing time. I wonder why ColdFusion would take the effort to apply any masks that were not supposed to be used in the DateFormat() function.



Reader Comments

This is definitely not covered in the docs. The only changes I see is that in MX they added full, long, medium, and short aliases.

Reply to this Comment

It's probably just a side-effect of the underlying algorithm. I can't imagine that this is useful in any way. Minutes don't work because the (m) maps to months in DateFormat(). And, TT for AM/PM doesn't do anything - it just comes back as TT in the resultant formatted string. If TT worked, I could maybe imagine using hTT as part of a DateFormat() call... but, oh well.

Reply to this Comment

It does seem like it would make more sense to just combine the two into DateTimeFormat() I get so annoyed with this line of code:
#DateFormat(now(), "m/dd/yyyy)# #TimeFormat(now(), "hh:mm:ss tt")#

Reply to this Comment

A group of jellyfish is called a "smack"

That is a more useless piece of information.

Reply to this Comment

I noticed this while working on performance optimization but I did not change it because it didn't hurt and more importantly, wanted to avoid any risk of breaking existing app even though it is undocumented. Sometimes backward compatibility makes you do strange things :-)

Reply to this Comment

@Rupesh,

Yeah, very true. Especially since it's not hurting anyone, just leave it alone. However, if there was a subset of TimeMasks that were documented to work in DateFormat(), I bet that would make a TON of people happy :)

Reply to this Comment

n = minutes in Dateformat()

All valid datepart masks:
yyyy - Year
q - Quarter
m - Month
d - Day
w - Weekday
ww - Week
h - Hour
n - Minute
s - Second

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.