0
<cfoutput> 
  <cfset mydate = 'June 01, 2008'> 
  <cfset JobStartDate=CreateODBCDateTime(mydate)> 
</cfoutput> 

Error: Date value passed to date function createDateTime is unspecified or invalid. Specify a valid date in createDateTime function.

Even isdate(mydate) // isdate('June 01, 2008') throws the exception. Even *DateDiff // DateDiff('m', 'June 01, 2008', 'October 14, 2010') also gives exception.

It works okay with other dates for example: 'August 01, 2008', 'May 14, 2012' etc

I am using ColdFusion 2021 Update 3. Any help would be highly appreciated?

Adding a few more details in response to the comments: Under JVM details Java Default Locale is en_US. Also by running GetLocale() gives me English (US). The issue does'nt reproduce on cftry or cffiddle. But it can be reproduced if you install Coldfusion via Commandbox and try running the code.

  • trycf.com does not recreate the problem - https://trycf.com/gist/c4a7889c7109c4a57380b0534fc7a10d/acf2021?theme=monokai – Dan Bracuk May 19 '22 at 11:56
  • @DanBracuk Tried on my machine and the getting the same error. Date value passed to date function createDateTime is unspecified or invalid. Specify a valid date in createDateTime function. The error occurred in C:/inetpub/Website/test.cfm: line 57 ``` 55 : date1 = 'June 1, 2008'; 56 : 57 : writeoutput(dateformat(date1, 'yyyy-mm-dd')); 58 : writeoutput(CreateODBCDateTime(date1)); 59 : ``` – Nisar Ahmad May 19 '22 at 12:57
  • 1
    Please provide a version that fails on trycf.com. It works fine for me as well. If it only fails on your machine, then there's something unique on your machine you need to troubleshoot. – Brad Wood May 19 '22 at 13:56
  • Also cannot reproduce the issue. I am guessing this is a locale issue. What locale are you? – haxtbh May 19 '22 at 14:05
  • Unable to reproduce. server.coldfusion.productversion = 2021,0,03,329779 (Windows). June 01, 2008 = {ts '2008-06-01 00:00:00'}. I've skipped the last 2 CF2021 updates. I'm waiting for Adobe to release a cumulative update that includes all the privately available hotfixes. Have you tried using ParseDateTime first? – James Moberg May 19 '22 at 15:05
  • @haxtbh Adding a few more details in response to the comments: Under JVM details Java Default Locale is en_US. Also by running GetLocale() gives me English (US). The issue does'nt reproduce on cftry or cffiddle. But it can be reproduced if you install Coldfusion via Commandbox and try running the code. – Mike Striker May 20 '22 at 06:21
  • I would look into your locale setting in CF and/or Java as that has the potential to affect date parsing. – Brad Wood May 20 '22 at 17:32

1 Answers1

0

Just do a lsParseDateTime to fix this. You are declaring that as a string so CF wont consider that as a date

<cfset JobStartDate = CreateODBCDateTime(lsParseDateTime(mydate, "en_US"))>
Marikkani Chelladurai
  • 1,430
  • 1
  • 13
  • 23