Text to date format in sql - sql

How can i convert the table containing date in text format DY Mon DD YYYY into DD MM YY date format which can be used for sorting when exported to a spread sheet.
The first date format is "Sun Jan 6 2013" which needs to be converted to "06-Jan-13" to be in date format not text which can be sorted on spread sheet and the type of the column is Text.
Thanks in advance.

You can convert the text you have to a DATE value, and then re-format it:
SELECT TO_CHAR(TO_DATE(date_column, 'DY MON DD YYYY'), 'DD MM YY')
FROM my_table

Related

How to insert DD MON YYYY format value into a date column in a snowflake table

My csv file has a date column having values in DD MON YYYY format eg: 28 Nov 2022.
When i tried inserting it into a date column(datatype= DATE) it is showing the below error. I have also tried using TO_DATE , TO_VARCHAR but getting the same error.
Kindly help me to resolve this.
Error: Date '28 Nov 2022' is not recognized
I want to insert the value in the same format (DD MON YYYY) into a column of date data type ,without changing the format i.e '28 Nov 2022'.
I was reading documentation (https://docs.snowflake.com/en/sql-reference/data-types-datetime.html#date) and i read: "DATE accepts dates in the most common forms (YYYY-MM-DD, DD-MON-YYYY, etc.)."
So i think the format you are trying to write is a no-supported date format.
you can:
format your date in a supported date format before write field in db.
write in a varchar datatype field, but in this case you'll lose all tools on date type.
I don't see other ways!

How to convert "Wed Jan 26 2022" to date in sql?

I have varchar like this "Wed Jan 26 2022"
I need to convert this to date in sql. How can i do this
for Sql Server:
convert(date, substring('Wed Jan 26 2022',5,11),9)
we ignore the Day name (superfluous), and convert the rest using format 9 indicating Mon dd yyyy format.
SQL*plus server (Here's my code) -
If I am right, you want such type of string which is an invalid one to convert that into a valid one so that you can store valid data into the database. then this code you can use->
SELECT TO_DATE('WED JAN 26 2022','DY MON DD YYYY')FROM DUAL;
(Explanation)->
Code will convert invalid date datatype to a valid date data type which is used in Oracle(SQL).
DY = Abbreviated Week Day
DD = Month day indicator
MON = Abbreviated month
YYYY = Four-digit year indicator

Dremio date conversation

How to convert date field "Dec 1 2018 6:38PM" to dd-mm-yyyy (01-12-2018)` in Dremio?
select to_timestamp('Dec 1 2018 6:38PM','mon dd yyyy hh:miAM')
Date/Time formats here: https://docs.dremio.com/sql-reference/sql-functions/datetime-formats.html

convert Date to DD-MMM-YY in redshift

I have a requirement to convert the yyyy-MM-dd date format into DD-MMM-YY.
e.g.: 2018-06-14 -> 14-JUN-18.
I tried to_char(date,'DD-MMM-YY'), however it's resulting in 14-06M-18.
Is this possible?
The format mask for the three letter month abbreviation in all caps is MON, not MMM:
to_char(date, 'DD-MON-YY')
Maybe you are coming from another API/language where MMM would have worked in that case.

Covert Time Stamp in HIVE

I have a date value (Mon Feb 29 06:01:14 CST 2016) in column. I need to convert this to the format 'YYYY-MM-DD' in hive.
Can any one please help me on this.
There is a unix_timestamp function which should help you. to_date(unix_timestamp(your_column, 'EEE MMM dd HH:mm:ss z yyyy')) This should return a string representing your date.