Skip to main content
Jan 31, 2019 4:28 PM UTC
Question

New to CF and seeking help with DateTimeFormat

Hi there,

I'm new to CF and trying to format a timestamp but no matter what I try I am unable to get the DateTimeFormat function to work successfully so I am hoping that some one with more experience might be able to quickly identify what I am doing incorrectly.

Goal: trim the timestamp

<cfscript>

     unformattedTime = "{ts '2018-11-05 12:13:50'}";

     formattedTime =  DateTimeFormat(unformattedTime, "yyyy-mm-dd HH:nn:ss");

       writeOutput(formattedTime);

</cfscript>

Expected Output: 2018-11-05 12:13:50

Actual output: nothing

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

EddieLotter
Inspiring
Jan 31, 2019 5:04 PM UTC

If you paste your example code into cfFiddle you will see it works as expected, however, you should probably use the CreateDateTime() function to initialize the unformattedTime variable.

Translate
Jan 31, 2019 5:15 PM UTC

Thank you for your reply. It is very much appreciated. I just realised that the reason its not working is that Im using an older version of CF that doesn't support the DateTimeFormat so I had to use the separate DateFormats and timeFormats to resolve it. Thanks again.

Translate
BKBK
Community Expert
Community Expert
Feb 2, 2019 2:50 PM UTC

Please mark the correct answer. It will help someone else in future.

Translate