I am trying to convert the string date type that retrieved from a column. Below is the scenario
#input
date_str
02/08/24
21/09/2023
25.02.16
null
null
I need to convert above column into a new column with below format
formated_col
02-aug-24
21-sep-23
25-feb-16
null
null
'date_str' column is the part of cte table when I used below query, just to test the conversion, it works for eg:
with test_table as (select * from basetable)
select t.*,
to_char(to_date(t.date_str, 'DD/MM/YYYY'), 'DD-MON-YY' ) as formatted_date
from test_table t
this create the expected output like this
formatted_date
02-aug-24
21-sep-23
25-feb-16
null
null
However when I am trying to create a table out of this, it
like
create table basetable as
with test_table as (select * from basetable)
select t.*,
to_char(to_date(t.date_str, 'DD/MM/YYYY'), 'DD-MON-YY' ) as formatted_date
from test_table t
It throws below error
day of month must be between 1
i am not able to understand where exactly is the issue?
date_strand the output are bugs, period. And if you assume this is extreme, Y2K quick-fix crick? 1920s come roaring back after mystery blip at UK's vehicle licensing agency, Y2K? How about Y2.02K as Lloyds suffers its second TITSUP* of the year, The Spanish family wrongly accused of child pornography due to a mistake reading a dateDD/MM/YYYYformat model (fiddle) as/will match other separators (unless you include theFXmodifier, which the OP hasn't). None of the data provided in the question generates the OP's error. One issue with the OP's query is that16would be matched as the year0016and not2016- to solve that, the OP would want theYY(which also matchesYYYYbut not vice versa) orRRorRRRR(depending on whether the OP would want to convert99to2099usingYYor1999usingRR/RRRR).DD/MM/YYYY. Why are you assuming that the order of the date terms does not match the details of the question when the OP's sample data provides no evidence to the contrary? Yes, other date formats can be used but the OP has not indicated that in their sample data or their code.