How do I convert the following timestamps to a simple date?
Thu Nov 29 18:00:00 CST 2018
Thu Apr 26 01:00:00 BST 2018
How do I convert the following timestamps to a simple date?
Thu Nov 29 18:00:00 CST 2018
Thu Apr 26 01:00:00 BST 2018
this will work:
select trunc(systimestamp), systimestamp from dual;
can also use :
Select to_char(to_date('15-JUN-16 22:54:39','DD-MON-YY
HH24:MI:SS'),'DD-MON-YY') from dual;
this code actually splits the data by space and extracts the values from specified index if you assume the space separated values as an array. and then combine it and converts it to date format
SELECT to_date(
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 3) ||' '||
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 2) ||' '||
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 6),'DD-MM-YYYY' )
FROM dual ;
you may also use like this:
SELECT to_date(
REGEXP_SUBSTR(columnname, '[^ ]+', 1, 3) ||' '||
REGEXP_SUBSTR(columnname, '[^ ]+', 1, 2) ||' '||
REGEXP_SUBSTR(columnname, '[^ ]+', 1, 6),'DD-MM-YYYY' )
FROM tablename;
updated code from your comments to add HH:MM AM/PM cst/gst:
SELECT to_char(to_timestamp(
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 3) ||' '||
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 2) ||' '||
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 6) ||' '||
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 4)
,'DD-MM-YYYY hh24:mi:ss' ),'DD-MM-YYYY HH:MI AM' )||' '||
REGEXP_SUBSTR('Thu Nov 29 18:00:00 CST 2018', '[^ ]+', 1, 5)
FROM dual ;
note: this would work only if all the data in your column is in above format.
the output would be a simple date like this: '29-11-2018' if you want the output to be '29-NOV-2018' you can replace the code with 'DD-MON-YYYY'