Skip to main content
Participating Frequently
Jun 10, 2021 12:32 PM UTC
Question

Migrating from CF 4.5 to 2018 on MS SQL Server

Migrating a few websites from CF 4.5 to 2018 (I know!) and could use some assistance.  Seems CF 2018 doesn't like my syntax:

<cfquery name="CalCount" datasource="#dsn#">
SELECT ID FROM Calendar
WHERE Approved = 1
AND Caldate > #now()# -1
AND WebsiteID=#application.WebsiteID#</cfquery>

Seems #now()# converts to{ts '2021-06-10 07:26:22'}
SELECT ID FROM Calendar WHERE Approved = 1 AND Caldate > {ts '2021-06-10 07:26:22'} -1 AND WebsiteID=1

CF doesn't seem to like my syntax. Will be digging into dates and formatting, but any insights appreciated.

 

    This topic is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    BKBK
    Community Expert
    Community Expert
    Jun 13, 2021 9:58 AM UTC

    You should use MS SQL's own date-functions. For example, in MS SQL,

     

     dateadd(day, -1, getdate())

     

    represents the date of yesterday. That way, you will solve the problem once and for all for any ColdFusion version. 🙂

     

    Translate
    Community Expert
    Jun 10, 2021 1:36 PM UTC

    Holy crap, I'm surprised that's the only thing that doesn't work!

     

    I would look at the DateDiff function in CF as the easiest resolution for this. I don't think you'll have to worry about formatting that way.

     

    Dave Watts, Eidolon LLC

    Translate
    Dave Watts, Eidolon LLC
    Participating Frequently
    Jun 10, 2021 2:26 PM UTC

    Thanks Dave,  Yep its pretty amazing, but just about everything is working.  My code is fairly straight forward - basic queries, if/then statements, setting variables, etc.  Believe it or not 99% of it is working like a charm!  I'm sure there are a few bugs I'll find along the way, but generally everything is working well.  Thanks for your input.  Cheers! 

    Chuck Ebbets

    Translate