I love ColdFusion's DateFormat() and TimeFormat() functions; they are hugely useful. And, most of the time, I use them independently of each other. But, often enough, I use DateFormat() followed by TimeFormat(). Wouldn't it be cool if ColdFusion had a DateTimeFormat() function that would accept both a date and a time mask? I think it would be, and here's what it might look like:
Launch code in new window » Download code as text file »
Using the above ColdFusion user defined function, you could easily format date/time values:
Launch code in new window » Download code as text file »
The above code would give us the following output:
22-May-2007 at 7:24 AM
May 22, 2007 at 7:24 AM
May 22, 2007 at the time of 7:24 AM
I'm sure this has been done before, but I just really hope that one day Adobe adds it to the ColdFusion built-in function list.
Download Code Snippet ZIP File
Comments (7) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
When Do You Violate The Law of Demeter In ColdFusion OOP Development?
Sending Random SMS Text Messages With ColdFusion To Make Her Feel Loved
Yup, Ray did it back in 2001 and has it on his cflib.org site http://www.cflib.org/udf.cfm?ID=134
cflib.org hasn't got much press lately and it's easy to forget the wealth of udf's on the site.
Posted by Christopher Wigginton on May 22, 2007 at 7:47 AM
@Chris,
It's funny, right after I posted this, I did a quick Google search to see if this was out there already (as I assumed it was) and there it was, CFLib as the second search result.
2001... I guess that means I'm only 6 years behind the Jedi :) The force is weak with me.
Posted by Ben Nadel on May 22, 2007 at 8:01 AM
Heh, people _do_ forget about CFLib, so it is no big deal. ;) I need to get off my ass and release that new version that I've been talking about since 2004. ;)
Posted by Raymond Camden on May 22, 2007 at 9:34 AM
Ben, good job anyway. If nothing else you made me aware of the existing function at cflib. Thanks!
Posted by Boyan on May 22, 2007 at 9:45 AM
@Ray,
Some of the best meals I have ever eaten were cooking over many many hours... that doesn't exactly translate to web sites, other than to say, good things are worth the wait.
Posted by Ben Nadel on May 22, 2007 at 9:47 AM
@Ray,
Are you ever going to just integrate cflib into riaforge?
Posted by anthony petruzzi on May 22, 2007 at 11:58 AM
No plans. I really look at RIAForge as more for 'projects', not single CFCs/UDFs/tags. Now that is NOT official RIAForge policy. Shoot, even I have a single CFC up there I believe. But in GENERAL those are my thoughts. (Have to treat carefully here. I admin both sites, but Adobe is the official owner of RIAForge. Etc etc etc.)
Posted by Raymond Camden on May 22, 2007 at 12:11 PM