I'm trying to convert/parse a string date of a format: MM/DD/YYYY or M/D/YYYY to a DATE("YYYY-MM-DD") in a column.
Create table date_test ( string_date TEXT );
insert into date_test values ('5/17/1967'), ('3/7/1936'), ('10/20/1930');
select string_date, "function to parse the string" as date_as_date from date_test;
-- Expected Result:
--------------------------------------
--string_date date_as_date
--------------------------------------
--5/17/1967 1967-05-17
--3/7/1936 1936-03-07
--10/20/1930 1930-10-20
-- I was trying to parse the date, but it gets a bit out of hand with the year:
SELECT substr('5/17/1967', 0, INSTR('5/17/1967', '/')) as Month;
SELECT substr(substr('5/17/1967', INSTR('5/17/1967', '/')+1), 0, INSTR(substr('5/17/1967', INSTR('5/17/1967', '/')+1), '/')) as Day;
I would love to use Regex, but SQLite doesn't support it. Any suggestion?