I am using DB Broswer for SQLite. I would like to retrieve information about the month and the day of the week for each sample.
SELECT Date
FROM Xtrain
returns
| Date |
|---|
| 26/04/2018 |
| 2/4/2018 |
I have tried using the TO_DATE statement.
Just to see if the function works I tried:
SELECT TO_DATE('2022-01-01','YYYY-MM-DD');
I get the following error:
Execution finished with errors.
Result: no such function: TO_DATE
At line 1:
SELECT TO_DATE('2022-01-01','YYYY-MM-DD');
Issue
There is no built in
TO_DATEfunction in SQLite.Fixing The Issue
The available date time functions can be found here https://www.sqlite.org/lang_datefunc.html. However, the functions expect/require the dates to be in a specific set of formats (which your data does not adhere to), see the link regrading formats.
As such you would need to reformat your date to either use the functions or to get the date in the format you require. Due to the format in which they are saved the reformatting is a little complex as you have to cater for single and double numeric characters in both the day of the month and the month of the year.
As an example using the
CASE WHEN THEN ENDconstruct, thesubstrfunction and the concatenate operator (||)you could use a query such as:-Demo
The following demonstrates use of the above:-
The result being:-
There are probably many ways, the above (imo) clearly shows all of the steps in detail (so may well be less concise than alternatives).
Really the correct solution would be to store the date in a consistent format and preferably one of the recognised formats. Doing so would afford full and direct data handling capabilities via the date and time functions.