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,246 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,246 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,246 Comments

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


Jul 12, 2007 at 12:20 PM // reply »
171 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,246 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,246 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 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
May 23, 2013 at 4:26 PM
ColdFusion QueryAppend( qOne, qTwo )
@Heather, Glad people are still getting value out of this! ... read »
May 23, 2013 at 3:49 PM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, I meant the code at the bottom (not the video). I did try to experiment with an intermediary variable, like: value = users.id[ i ]; arrayContains( userIDs, value ); ... but t ... read »
May 23, 2013 at 11:06 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Are you talking about As Number: YES As String: YES As Java: YES? If so, that's with 3 different ways of referencing the constant 1, not users.id[1]. Query object references(*) are what seem ... read »
May 23, 2013 at 9:55 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Dan, According to the CF Admin, I'm running Java "1.6.0_45". As far as the DB column, in the database it's an INT. I'll see if I can dig into what CF sees it as. @WebManWalking, But h ... read »
May 23, 2013 at 9:49 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, I think the problem is that we're used to loose typing in ColdFusion, like JavaScript. If a value is a number but it's needed in an expression to be a string, noooo problem. I've encountered ... read »
May 23, 2013 at 9:47 AM
ColdFusion QueryAppend( qOne, qTwo )
You rock! Thank you, thank you, thank you!!! ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools