The datatype of DATEInvoice is VARCHAR
From the image above, if I want to select the information of the invoice from specific time let say from 1-12-2020 00:00:00 to 13-12-2020 23:59:00, how can I write? I have try many ways to write. For example,
SELECT * FROM INVOICE WHERE DATEINVOICE BETWEEN To_date('01-12-2020 00:00:00','dd-mm-yyyy HH24:MI:SS') AND To_date('13-12-2020 23:59:00','dd-mm-yyyy HH24:MI:SS')
**BUT THE RESULT I GET IS RETURN ZERO ROWS. Hope anyone can help me, I am having trouble on this.
2
Answers
First, you can simplify your logic to:
In some databases, you should identify date constants with the (standard)
DATE
keyword:This assumes that
DATEINVOICE
is stored as a valid datetime/timestamp value in your database. If it is a string, then it has the wrong type. You should fix your data model. If someone else has created such a broken data model, then you can convert the value in theWHERE
clause:However, the effort should really be on fixing the data model.
Can use Please try MySQL’s DATE() function:
You could also try this: