Strange phenomenon with parseDateTime()

Hi,

In the process of porting CF 2016 code to Lucee 5.4.6.9
But run into this problem:

<cfset local.dt1 = parseDateTime("2024-10-25 14:30:00", "yyyy-MM-DD HH:nn:ss")>
<cfoutput>#dt1#</cfoutput>

Results in Lucee 4.5 & Coldfusion: {ts ‘2024-10-25 14:30:00’}
But in Lucee 5.x / 6.x : {ts ‘2024-01-25 14:30:00’}

When I change the parse pattern to “yyyy-MM-dd HH:nn:ss” it works as expected: {ts ‘2024-10-25 14:30:00’}
According to the docs, dd and DD should result the same.

I could change my (large) codebase, but was hoping to avoid that.

Thanks!

Gunter

This is strange, but I see both formats being parsed incorrectly on trycf.com also on CF2021/23 also:

<cfscript>
writedump(ParseDateTime("2024-10-25 14:30:00","yyyy-mm-DD HH:nn:ss"));
writedump(ParseDateTime("2024-10-25 14:30:00","yyyy-MM-DD HH:nn:ss"));
</cfscript>

Maybe there is something wrong with the underlying Java method?

1 Like

Hmm, interesting indeed. I am running Lucee with Java 11.0.23
Didn’t check CF 2021/2023 because we have those not running here. Thanks for pointing that out!
I guess I’ll need to change my (large) codebase for this, no problem.

Thanks!

1 Like

Apparently, Lucee (and CF 2021/2023 as well), is using the java function SimpleDateFormat:
https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
And according to those docs, there is indeed a difference between D and d in the format string:

D Day in year Number 189
d Day in month Number 10

Maybe Lucee 4.5 and CF < 2021 was using something else under the hood.

Gunter

3 Likes

I don’t recall in which version of Lucee the change was made…
But I do distinctly recall having the same issues.

Subsequently, I too had to change all the date/datetime masks that were in our code - thankfully we use only a couple of different masks so a simple regex was able to correct all instances in just a few separate find/replace operations.

@Gunter that may is an option for you, so not have to change your code

the class name of DateTimeFormat is lucee.runtime.format.DateTimeFormat

2 Likes