Hours And Seconds Work In ColdFusion DateFormat()

Posted July 12, 2007 at 8:10 AM by Ben Nadel

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

Jul 12, 2007 at 8:28 AM // reply »
319 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 »
11,238 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 »
11,238 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 »
11,238 Comments

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


Jul 12, 2007 at 12:20 PM // reply »
170 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 »
11,238 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 »
11,238 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 :)


Jun 17, 2010 at 3:02 AM // reply »
1 Comments

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


Rob
Oct 28, 2010 at 3:26 PM // reply »
1 Comments

I think you all need smacked :D


Post A Comment

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.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 20, 2013 at 4:38 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, Your confusion is well founded, since this is a very confusing features. In fact, it ONLY works if you use array notation. Meaning, that this: arrayToList( query[ "columnName" ] ) ... read »
May 20, 2013 at 4:34 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I was thinking chicken and the egg, I wouldn't have expected it to work in the valuelist going in I guess. Maybe I just need a beer, long day :) ... read »
May 20, 2013 at 4:29 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Dana, That's if you're trying to reference a specific row. In this case, we're trying to reference the entire query column as one cohesive value. So, you are correct that if you wanted to output a ... read »
May 20, 2013 at 4:24 PM
Using A Dynamic Column Name With ValueList() In ColdFusion
I thought when you used array notation to reference queries you always had to have the row or it would throw a similar error as well? ... read »
May 20, 2013 at 11:45 AM
Using jQuery's Animate() Step Callback Function To Create Custom Animations
This is really useful. I found out that you don't actually have to use a dummy css property (surprisingly). To animate a property in a linear-gradient for instance I did this this.css('someLinearGra ... read »
May 20, 2013 at 10:51 AM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Josh, Oh snap! You're totally right! I'm not sure I've ever tried that. I did know that you can call a number of other array-methods on ColdFusion query columns: http://www.bennadel.com/blog/167 ... read »
May 20, 2013 at 10:45 AM
Using A Dynamic Column Name With ValueList() In ColdFusion
@Ben - I believe you can achieve the same functionality with ColdFusion's built in ArrayToList() function. ArrayToList( users[ "id" ] ); ... read »
May 20, 2013 at 10:21 AM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
Is there any error logging and handling framework in angularjs, if not then in what way I can do this. ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools