Skip to main content
WolfShade
Brainiac
November 4, 2025
Question

Code that worked for years suddenly glitches - CF2021 > CF2023

  • November 4, 2025
  • 3 replies
  • 243 views

Hello, everyone.

 

About a week ago, our SA and DBA started a migration from CF2021 to CF2023, we are experiencing a couple of odd issues, and the weird thing is - it's limited to just one project.  No other projects are experiencing these issues.  The issue is in our custom built Workflow application.

 

One issue is with setting an identifier for a user using data pulled from the user's Common Access Card (CAC).  We are pulling the DoDID (lastName.firstName.middleName[.cadenceName].EPIDnumber) and I'm getting the 10 digit EPID from this string that is in the CGI scope.

 

<cfset session.userepid = REMATCH("\d{10}",cgi.SSL_CLIENT_S_DN_CN)[1] />

The number that is in the DoDID can be either a 10 digit number, or a 16 digit number.  So I'm looking for all 10 digit numbers and taking the first position in the array as the desired number.  This is the actual EPID.  But I'm getting an error that position 1 of the array doesn't exist.  I can output the whole DoDID before that point, do the rematch and get an array length of 1 from my CAC, and abort the page - it works.  But as soon as I comment out that added code and abort, it gets to the above line in the code section and throws an error saying that it can't find anything in the array.  Stops processing.

 

Another issue we are having has to do with DateDiff.  For years, we've been converting the dates pulled from the database using to_char(dateObject, 'YYYY-MM-DD').  But we are getting an error stating that the value supplied to the cfoutput is "unspecified or invalid".  Dumping the data shows all dates in the query are proper dates.  Only thing I can think of is maybe CF2023 handles empty dates differently than CF2021 does??

 

Any thoughts appreciated.

 

V/r,

 

WolfShade

 

UPDATE:  My DBA suggested I use ParseDateTime() around the values.  I did, and the first date wasn't an issue - it worked - but the second date threw an error for ParseDateTime() (no end date had been entered, and CF didn't like '' as a value.)  I placed a cfif around it so it would process the second date ONLY if there was a value other than '', and that worked.

 

But when it got to DateDiff, that error happened.  Apparently it doesn't like that second date being a blank/null.  This has been working with no problem for years.  Why it suddenly flips out over a blank date ...

    3 replies

    Charlie Arehart
    Community Expert
    November 5, 2025

    I've read all the replies so far. If you remain stumped after doing what bkbk and Pete have suggested, then please do this:

    1. Dump cgi.SSL_CLIENT_S_DN_CN right before the code that's failing. Is it indeed an array? And is array element 1 what you'd expect?
    2. Dump to_char(dateObject, 'YYYY-MM-DD') and separately just dateobject just before the line using those. Do those have what you expect. 
    3. Please don't presume other similar dumps in other places prove "you've done it already": do those, right there (to a file if you must). Let us see the value of the date dumps. 
    4. If you remain stumped, you may be presuming there's a problem with CF or perhaps your application.cfc/cfm. In that case, please create a standalone few-line program that demonstrates the problem.
    5. Then try running that on its own folder with its own empty application.cfc. Does the error/unexpected behavior persist?
    6. If so, run that code on cffiddle.org or trycf.com, both of which will let you run it against different cf versions.
    7. If it fails on them, on different versions, do you have some environment where this demo code runs well? If so, tell us it cf version and update level that is. Maybe it's on an older update (those sites don't let you try different update levels). You might want to share the few-line demo here for us to try. Some of us can test on different update levels. 
    /Charlie (troubleshooter, carehart. org)
    WolfShade
    WolfShadeAuthor
    Brainiac
    November 5, 2025

    Hi, @Charlie Arehart!

     

    If I dump cgi.SSL_CLIENT_S_DN_CN, it's a string.  My DoDID: lastName(dot)firstName(dot)middleName(dot)cadenceName(dot)EPID.  The REMATCH finds my 10 digit EPID with no issues, creating an array with a length of 1, if I abort before the line that saves it to a session variable.  I can display that EPID.  It's when I comment out that code and let it get to the part where it saves that to a session variable that it throws an exception.

     

    I'll give your suggestions a shot, and even create a scratchpad file for testing.  I'll report back here with my findings.

     

    Thank you.

     

    V/r,

     

    WolfShade

     

    UPDATE:  The issue with the EPID has cleared itself up.  I changed no code regarding it.  No one has informed me that there was any config or settings change.  It just started working.  Focusing on the DateDiff issue.

    BKBK
    Community Expert
    November 6, 2025

    Hi, @11836390_Arehart!

     

    I updated my earlier post.  I have no idea why it just started working with the EPID.  No idea why.

     

    I'm focusing on the DateDiff() error.  I'll follow your suggestions and report my findings.

     

    Thank you.

     

    V/r,

     

    WolfShade

     

    UDPATE:  Wanted to try something before I engaged in your suggestions.

    I placed a CFTRY/CFCATCH around the line that is reported as the issue, and set it to display the begin date and end date, and had to manually add a cfset for variables.diffdate (the variable that the DateDiff() value is being set to.)  Reloaded the page, and the very first record that didn't have an end date is what triggered the error.  The value of qry.end_date is "[empty string]".  Now, this I can see would not work well in a DateDiff() function.  But why did it work for so long, then suddenly start pushing [empty string] for a blank date?


    quote

    The value of qry.end_date is "[empty string]".  Now, this I can see would not work well in a DateDiff() function.  But why did it work for so long, then suddenly start pushing [empty string] for a blank date?


    By @WolfShade

    Two words: ColdFusion updates. ColdFusion's updates strive to remove ambiguous or incorrect functionality from the language. Especially in recent years. So, what was ignored or allowed in a previous update might result in an error in the current update.

    BKBK
    Community Expert
    November 4, 2025
    • "Position 1 of the array doesn't exist"
      My guess is that sometimes cgi.SSL_CLIENT_S_DN_CN does not contain a ten-digit substring. You can verify this by using try/catch.
      In the following example, when the error occurs, the CGI scope is dumped - out of the user's sight - as an HTML file which you can examine later.
      <cftry>
      	<cfset session.userepid = REMATCH("\d{10}",CGI.SSL_CLIENT_S_DN_CN)[1] />
      	<cfcatch type="any">
      		<cfdump var="#CGI#" label="CGI dump: implies CGI.SSL_CLIENT_S_DN_CN does not contain ten-digit substring" format="html" output="#server.coldfusion.rootDir#\logs\CGI.SSL_CLIENT_S_DN_CN.dump.html">
      	</cfcatch>
      </cftry>
      ​

      Is cgi.SSL_CLIENT_S_DN_CN then what you expected

    • Invalid date and datetime values
      The database may format dates and datetimes differently from your application. Even ColdFusion code based on different locales do represent dates differently. 
      So, I'd say the moral is: validate date values and datetime values before using them, especially if they're coming from another party
      Some relevant validation functions:
      IsDate
      IsValid
      LSIsDate
       
    WolfShade
    WolfShadeAuthor
    Brainiac
    November 5, 2025

    Hi, @BKBK!

     

    I have verified that my EPID is, indeed, in my DoDID being returned by cgi.SSL_CLIENT_S_DN_CN.  I was able to output my DoDID to the screen, perform the REMATCH against it using "\d{10}" and got an array length of 1.  Outputting the first position of the array then aborting any further page processing shows my 10 digit EPID.  It's there.  I just can't understand why it doesn't see it when trying to save it to a session variable, on the very next line (once the abort has been commented out.)

     

    As far as the date goes, the to_char() is formatting the date as YYYY-MM-DD and passing the string version to the DateDiff() function.  This worked fine under CF2021.  And what's more perplexing is that it worked under CF2023 until late last week.  Thu/Fri, it started giving us fits, and only on this one project.  No other projects have been negatively affected.

     

    The documentation for DateDiff() is giving a mixed message as far as what to provide DateDiff() - first example passes string value dates (date1 = "2018-09-25"), the second example passes a date object (Date1 = "{ts '2018-11-15 12:13:50'}").  I've tried both, no success.  I've tried removing the to_char() from the query, no success.

     

    As far as I can tell, the only difference between this project and other projects is - this uses application.cfm, not .cfc.  No one bothered updating to application.cfc because it just worked.

     

    V/r,

     

    WolfShade

     

    UPDATE:  I just checked the database, and the begin and end date columns are formatting as YYYY-MM-DD, some with actual hours/minutes/seconds/ms, others with 00:00:00.0.  It's been this way since before I started working here in 2012.

    pete_freitag
    Participating Frequently
    November 4, 2025

    @WolfShade for your DateDiff issue, there is a breaking change introduced in CF2021 with date masks. The uppercase D now means day of year, instead of day of month. Change your date mask to lowercase to fix. Details here: https://www.petefreitag.com/blog/coldfusion-compatibility-scan/ 

     

    Since you are already on CF2021, perhaps you had specified the JVM argument: -Dcoldfusion.datemask.useDasdayofmonth=true to override this behaviour. 

    WolfShade
    WolfShadeAuthor
    Brainiac
    November 4, 2025

    Hi, @pete_freitag !  

     

    It's possible that the SA may have added that JVM argument.. I'll ask.

     

    Meanwhile, I'm going to update my original post.  There has been minor progress.  😄

     

    WolfShade