简体   繁体   中英

What is the correct syntax for SQL Statement using MySQL

In access i used this and its works fine:

(tblReservations_Dates.Date) Between #" & dteBegDate & "# And #" & dteEndDate & "# 

Using MySQL I used this:

(tblReservations_Dates.Date) Between '" & dteBegDate & "' And '" & dteEndDate & "'

However the data is not displayed I was just wondering if this is the correct syntax for SQL Statement for comparing dates?

  1. You don't need the brackets around the table.column reference
  2. You need to make sure the query is submitting the start & end values in the proper datattype - date in this case.

Use STR_TO_DATE to safely convert whatever you're providing into a date datatype for MySQL. If you provide the date format, I'd be happy to update my answer with an example.

You need to make certain that the date strings (dteBegDate and dteEndDate) are in the format expected by MySQL, which would be YYYY-MM-DD HH:MM:SS. So, right now would be

2009-11-25 21:45:52

(in Pacific time). Other than that, it should work fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM