Announcement

Collapse
No announcement yet.

Wierd MySQL Query problem - date string is being mathematically operated on??

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wierd MySQL Query problem - date string is being mathematically operated on??

    Hello loyal AMS helpers!

    I've got a weird problem where a string within a MySQL query is being "math-ed", lol. I'll explain....

    consider a string (specifically an ISO formatted date) coming from:

    dateISO = System.GetDate(DATE_FMT_ISO);

    is included in a MySQL query. But when the query executes, the string "2019-11-14" is becoming "1994" (which is 2019 minus 11 minus 14).

    as I'm typing this out, I'm vaguely remembering that I may have used a global function in the past to inject a string variable in a query, versus just a numeric variable. But I couldn't find that when searching.

    Here's the query: I'm sure now its how I'm concatenating the variable, so any help would be greatly appreciated!

    result = MySQL.Query("UPDATE table SET renewDate = "..dateISO.." WHERE id = 1");

  • #2
    Nevermind. I found it. Explaining below for future reference for others (or myself, lol)

    The string in the query has to be enclosed by quotes. A simple way of doing this is using a global function similar to:

    Code:
     
     function Quote(strText)      --returns the supplied string as a quoted string.      return string.format("%q", strText); end

    Comment


    • #3
      thanks for share

      Comment

      Working...
      X