Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Can't update date field with a variable

Contributor ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

I have a DB with a date field that I need to update periodically. I'd like to set a date on the same template where I insert the record. 

 

I run my insert query, then run a select query for maxID to get the data row. I set a session variable with a calculated date, and I want to "set" that date in the field with an update query. In the following code, setting the value as "2021-09-17" will update the field, as I desire. But, if I try to use my session variable for the update, it doesn't work. I've tried every variation on syntax I can conceive of, and nothting works. 

 

After the form action, debugging on my page shows that the variable exists and holds a value. Is there a chance that it doesn't get set before the update query fires? 

    <!--- Set ExpireDate column --->
    <cfquery datasource="#APPLICATION.dsn#">
        UPDATE tbl_user
        <!---SET ExpireDate = "#session.ExpireDate#"--->
        SET ExpireDate = "2021-09-17"
        WHERE UserID = '#session.UserID#'
        </cfquery>

I have no doubt the solution is simple, but it escapes me.

 

~john

TOPICS
Advanced techniques

Views

283
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Aug 17, 2021 Aug 17, 2021

Use the CreateOdbcDate() function.

Votes

Translate
Contributor ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Out of curiosity, I inserted the following code between my insert query and update query to test for the contents of the variable. 

    <cfif len(trim(session.expiredate))>
        <cflocation url="/index.cfm?value=#session.expiredate#">
    </cfif>

This is my result: "http://localhost:8502/index.cfm?value=17-Sep-21"

So, indeed, the variable has a value.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

Use the CreateOdbcDate() function.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

I should take a picture of my face with my best "DOH!" expression on it.

 

Thanks so much, Eddie!

 

~john

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 17, 2021 Aug 17, 2021

Copy link to clipboard

Copied

LATEST

You're welcome. 🙂

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources