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

Hi all

Thank you for your replies. Unfortanetly i can’t make it work.

This is the sourcecode - executed on CF9

<cfoutput>#GetLocale()#</cfoutput><br>
<cfoutput><cfset SetLocale('de_CH')></cfoutput>
<cfoutput>#GetLocale()#</cfoutput><br>

<cfset past_date = "#LSDateFormat("11.10.2014", "dd. mmm yyyy")# #LSTimeFormat("01:00")#">
<cfset current_date = "#LSDateFormat(Now(), "dd. mmm yyyy")# #LSTimeFormat(Now())#">

past_date: <cfoutput>#past_date#</cfoutput><br>
current_date: <cfoutput>#current_date#</cfoutput><br>

<cfset diff_months = #DateDiff("m", "#past_date#", "#current_date#")# >
diff_months: <cfoutput>#diff_months#</cfoutput>

This throws this output:

German (Swiss)
German (Swiss)
past_date: 11. Okt 2014 01:00
current_date: 07. Nov 2022 19:42
diff_months: 96

This is the sourcecode - executed on Lucee (locale is in a different fomat, everything else is identical):

<cfoutput>#GetLocale()#</cfoutput><br>
<cfoutput><cfset SetLocale('swiss german')></cfoutput>
<cfoutput>#GetLocale()#</cfoutput><br>

<cfset past_date = "#LSDateFormat("11.10.2014", "dd. mmm yyyy")# #LSTimeFormat("01:00")#">
<cfset current_date = "#LSDateFormat(Now(), "dd. mmm yyyy")# #LSTimeFormat(Now())#">

past_date: <cfoutput>#past_date#</cfoutput><br>
current_date: <cfoutput>#current_date#</cfoutput><br>

<cfset diff_months = #DateDiff("m", "#past_date#", "#current_date#")# >
diff_months: <cfoutput>#diff_months#</cfoutput>

But this throws this output:

english (us)
Swiss German
can’t cast [11. Okt 2014 01:00] to date value
17: <cfset diff_months = #DateDiff(“m”, “#past_date#”, “#current_date#”)# >

If i try to use the suggenstion from above (lsparsedatetime) by using this sourcecode executed on Lucee:

<cfoutput>#GetLocale()#</cfoutput><br>
<cfoutput><cfset SetLocale('swiss german')></cfoutput>
<cfoutput>#GetLocale()#</cfoutput><br>

<cfset past_date = lsparseDateTime(date="11.10.2014 01:00", format="dd. MMM yyyy hh:mm")>
<cfset current_date = lsparseDateTime(date="Now()", format="dd. MMM yyyy hh:mm")>

past_date: <cfoutput>#past_date#</cfoutput><br>
current_date: <cfoutput>#current_date#</cfoutput><br>

<cfset diff_months = #DateDiff("m", "#past_date#", "#current_date#")#>
diff_months: <cfoutput>#diff_months#</cfoutput>

Then i get this error:

english (us)
Swiss German
Unparseable date: “11.10.2014 01:00”
<cfset past_date = lsparseDateTime(date=“11.10.2014 01:00”, format=“dd. MMM yyyy hh:mm”)>

Does somebody having an idea how to make this work or does know what i’m doing wrong?

Regards
Tom

Coldfusion 9 used JRUN, which worked kinda different.


<!--- <cfdump var="#getLocale()#"> --->
<cfoutput>#GetLocale()#</cfoutput><br>
<cfoutput><cfset SetLocale('de-CH')></cfoutput>
<cfoutput>#GetLocale()#</cfoutput><br>

<cfset mytime1 = #dateTimeFormat("11/20/2014 01:00", "medium")# >
<cfset mytime2 = ParseDateTime(mytime1)>

<cfset past_date = #lsparseDateTime(#mytime2#, 'de-CH', "dd. MMM yyyy hh:mm")# >
<cfset current_date = lsparseDateTime(Now(), 'de-CH', "dd. MMM yyyy hh:mm")>

past_date: <cfoutput>#past_date#</cfoutput><br>
current_date: <cfoutput>#current_date#</cfoutput><br>

<cfset diff_months = #DateDiff("m", "#past_date#", "#current_date#")#>
diff_months: <cfoutput>#diff_months#</cfoutput>
2 Likes

Thank you @Terry_Whitney @cfmitrah

2 Likes