Hours And Seconds Work In ColdFusion DateFormat()

Posted July 12, 2007 at 8:10 AM

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:

 Launch code in new window » Download code as text file »

  • #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.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Print Page



Learning ColdFusion 9 - ColdFusion 9 tutorials, samples, examples, demos

Reader Comments

Jul 12, 2007 at 8:28 AM // reply »
235 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.


Jul 12, 2007 at 8:37 AM // reply »
7,572 Comments

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.


Jul 12, 2007 at 8:47 AM // reply »
8 Comments

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")#


Jul 12, 2007 at 8:54 AM // reply »
7,572 Comments

@Jeremy,

Exactly. I am sure Ray will tell you that that UDF is up on CFLib.org. I also wrote one a while back as well:

http://www.bennadel.com/index.cfm?dax=blog:717.view


Jul 12, 2007 at 9:18 AM // reply »
20 Comments

A group of jellyfish is called a "smack"

That is a more useless piece of information.


Jul 12, 2007 at 9:22 AM // reply »
7,572 Comments

Ha ha. Now would that be a "smack of jellyfish" or is that redundant?


Jul 12, 2007 at 12:20 PM // reply »
124 Comments

So if you do a belly flop into a pool of jellyfish, does that mean you just belly smacked and smacked a smack?


Jul 12, 2007 at 12:25 PM // reply »
7,572 Comments

Can you be more spineless than a smack?


Jul 13, 2007 at 3:52 AM // reply »
25 Comments

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 :-)


Jul 13, 2007 at 7:32 AM // reply »
7,572 Comments

@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 :)


Post Comment  |  Ask Ben

Recent Blog Comments
Mar 22, 2010 at 7:43 AM
Terms Of Service / Privacy Policy Document Generator
Thankyou for this very helpful form. You've made my life much easier today. I'll have a look around your site... I'm sure there's some more good stuff here..Thanks Dave ... read »
Mar 22, 2010 at 7:21 AM
Encountered "(. Incorrect Select Statement, Expecting a 'FROM', But Encountered '(' Instead, A Select Statement Should Have a 'FROM' Construct.
I got this exception now. In case you're using var-es local struct, CF gives you couple of "new" exceptions: Encountered "local. and Encountered "id. Incorrect Select List, Incorrect select colum ... read »
Mar 22, 2010 at 3:08 AM
Ask Ben: Selecting XML Attributes Given Other XML Attributes
Thanks for the response. I finally discovered that I was getting this error because I had cfsetting enablecfoutputonly="yes" in Application.cfc, and was neither setting it to false elsewhere nor brac ... read »
Mar 21, 2010 at 8:57 PM
The Bourne Ultimatum Starring Matt Damon And Julia Stiles
late to the party, but my observation is this: rewatch carefully for the platonic nature of the relationship between nicki and jason. she never flirts with him. he never comes on to her. they alway ... read »
Mar 21, 2010 at 7:40 PM
Is Simulating User-Input Events With jQuery Ever A Good Idea?
A couple of things. One you embed the initial state of of more-info in the CSS. IMHO, that behavior should be in jQuery: moreInfo.hide(); It shows that the behavior your toggling and closing is mor ... read »
Mar 21, 2010 at 3:59 PM
Exploring ColdFusion Component Runtime Class Properties And Serialization
@Elliott, according to Ben's experiment, serializeJSON() doesn't access the private data by default - it doesn't even access the getHair() method - so trying to clone a Girl.cfc via serializeJSON/des ... read »
Mar 21, 2010 at 3:49 PM
Ask Ben: Javascript String Replace Method
I'm confused a bit by what you are asking, but if had this sentence: The color, red, is in the style statement; style: red;. and wanted to remove all or change all of the commas, colons, and semi-c ... read »
Mar 21, 2010 at 3:13 PM
Ask Ben: Javascript String Replace Method
I am trying to make a java program to count the number of times that these punctuation marks occur in a body of text: , : ; . ! - ' " ? / \ I am using this piece to ferret out the commas: numcommas ... read »