Can't cast [] to date value - v2

Hi all

I’m migrating an app from CF9 to Lucee (both runs on the same server). I’m using this to format a date:

<cfset SetLocale(‘de_CH’)>
<cfset past_date = “#LSDateFormat(“11.10.2014”, “dd. mmm yyyy”)# #LSTimeFormat(“01:00”)#”>

Works smooth with CF9, but after switching over to Lucee i get this when i compare the date:

can’t cast [11. Okt 2014 01:00] to date value

The Error Occurred in

703: <cfset past_date = “#LSDateFormat(“11.10.2014”, “dd. mmm yyyy”)# #LSTimeFormat(“01:00”)#”>
704: <cfset current_date = “#LSDateFormat(Now(), “dd. mmm yyyy”)# #LSTimeFormat(Now())#”>
> 705: <cfset diff_months = #DateDiff(“m”, “#past_date#”, “#current_date#”)# >
706: <!— <cfset diff_months = #DateDiff(“m”, “#LSDateFormat(”#past_date#")#", “#LSDateFormat(”#current_date#")#")# > —>
707: <cfset diff_months_minus1 = #DateDiff(“m”, “#past_date#”, “#current_date#”)# - 1>

I only found this one related to the error message:

Does somebody know a way to make this work?


Win2k16
JAVA_VERSION=“11.0.3”
Tomcat 9.0.14
Lucee 5.3.8.206

I think the main problem is that you are comparing strings, not date/time vaues. lsdateformat parses dateobject to strings, so you are using datediff to compare strings. The cfengine then will try to cast the strings to datetime values for comparison.

But could you create a gist on trycf.com so we can reproduce the issue?

The above example failed in all versions of ACF and lucee in trycf

But using lsDateTimeFormat() works for me in Lucee

lsparseDateTime(date="#past_date#", format="dd. MMM yyyy hh:mm")

Note: LSParseDateTime() need a mask from SimpleDateFormat (Java Platform SE 8 )

1 Like