Shaun Kulesa <
[email protected]> wrote:
Hello,
I am trying to get records between two dates, the date field is the
TEXT data type.
I got this working for dates in the same month, this will return
values for each day: "SELECT * FROM customer_orders WHERE stock_id=?
AND date BETWEEN '27/03/2023' AND '31/03/2023'"
This does not work for separate months though, if I do it will return nothing: "SELECT * FROM customer_orders WHERE stock_id=? AND date
BETWEEN '27/03/2023' AND '01/04/2023'"
Should I be doing this another way?
Do you have freedom to 'redo' the database table?
If yes, then change the date column to be one of two items:
1) If you want to stick with 'text' colums, use an ISO8601 style date:
YYYY MM DD (i.e. YYYY-MM-DD or YYYY/MM/DD). This format has the
advantage that the ASCII text sort order of the strings is *also* a
sort in date order. This will let your 'between' query actually find
dates that are 'between' those values
2) Switch the dates to be unix epoch integer values, then a normal
integer range will find 'between' values.
And, note that for 'display' purposes, you can display whatever format
a user wants externally, independent of the format you use inside the
DB.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)