Timestamp conversion failure in SAS Hive - hive

Its a hive in SAS.
Its working in a particular case.
For example.
proc sql;
connect to hadoop;
select dt, unix_timestamp(dt, "EEE MMM dd HH:mm:ss zzz yyyy') from log
disconnect to hadoop;
quit;
Its result is not problem. Sun DEC 01 17:00:00 KST 2019, 122233....
But when I use substring
select dt, unix_timestamp(dt, "EEE MMM dd HH:mm:ss zzz yyyy')
from log where substring(dt, 25, 4)='2019'
timestamp value is turn to null.
And
create table log_temp as
select dt, unix_timestamp(dt, "EEE MMM dd HH:mm:ss zzz yyyy') from log
Its also make it null
Do you know what's the problem?

The year part of the date time representation in the log table starts at position 25, not position 20
EEE MMM dd HH:mm:ss zzz yyyy
1234567890123456789012345678
where substring(dt,25,4) = '2019'
should work

Related

Convert YYY-MM-DD to MON DD, YYYY in PostgreSQL

I am having difficulty converting dates in a column from YYYY-MM-DD to Mon DD, YYYY
I think I first need to reorganize the dates and then use a case when statement to specify 01 = Jan and so on? Is that correct?
SELECT to_date(column_name, 'MM/DD/YYYY')
FROM table
gives me some incorrect dates
i.e. previous = 2012-01-29 and
result from query = 0197-06-26
Any suggestions? Thanks
I figured it out!
SELECT to_char(date(column_name), 'Mon dd, yyyy')
FROM table
gives me exactly what I need without the need of a case statement.

Can't find good Date Format : impossible parsing

I'm trying to convert the following String to a datetime format:
Sat Jan 14 13:55:34 CET 2017
If we consider that my date is in the in_OutPut3 variable, I'm trying to use the following format pattern :
TO_DATE(in_OutPut3,'DY MON DD HH:MI:SS Z YYYY')
I receive the following error :
The system failed to parse the date format : 'DY MON DD HH:MI:SS Z
YYYY'.
Do you have any idea what is this date format ?
You have a timezone embedded in your string so try using the TO_TIMESTAMP_TZ function. TO_DATE is not designed to work with timezones.
The following works on 11g;
select to_timestamp_tz('Sat Jan 14 13:55:34 CET 2017','DY MON DD HH24:MI:SS TZR YYYY') from dual
This one worked for me:
to_timestamp('Sat Jan 14 13:55:34 CET 2017','Dy Mon dd hh:mi:ss ZZ yyyy');
Marco
You can just ignore the timezone while converting to Informatica Date type. Anyway, Informatica won't retain timezone information after converting to Data datatype. Put some symbols like underscore(_) to match 'CET'
TO_DATE(in_OutPut3, 'DY MON DD HH24:MI:SS ___ YYYY')
Also, looks like you have the hours in military format. In that case you have to use HH24.

TO_DATE function time zone parse error

I have a problem when trying to parse a date in Oracle:
TO_DATE('Fri May 16 14:30:57 EDT 2014', 'DY MON DD HH24:MI:SS TZD YYYY')
Error:
ORA-01821: date format not recognized
What is wrong with the timezone?
This one works:
select TO_TIMESTAMP_TZ('May 16 14:30;57 EDT 2014', 'MON DD HH24:MI:SS TZD YYYY')
from dual;

Text to date format in 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

convert date in sql using to_char function

I would like to convert the following date to this format(DD-MON-YYYY).
I tried executing the below query but I got the error saying "date format not recognised".
select to_char(to_date('Sat Dec 01 00:00:00 IST 2012','EEE Mon dd HH:mm:ss z yyyy'),'DD-MON-YYYY') from dual;
For everything but the time zone:
'DY MON DD HH24:MI:SS YYYY'
For timezone support you need to use a conversion function that supports a timezone like TO_TIMESTAMP_TZ() and have the time zone name as one Oracle recognizes in the form it recognizes.
select to_char( TO_TIMESTAMP_TZ(
REPLACE( 'Sat Dec 01 21:00:00 IST 2012','IST','Asia/Calcutta'),
'DY MON DD HH24:MI:SS TZR YYYY'),'DD-MON-YYYY') from dual;
The relation between time zone names and abbreviations is one to many for most.
SELECT tzname, tzabbrev FROM v$timezone_names where TZABBREV = 'IST'
For your example it would probably be easier to remove some or all of the date parts you don't need in the output before conversion.
select to_char( to_date( replace('Sat Dec 01 21:00:00 IST 2012','IST',''),
'DY MON DD HH24:MI:SS YYYY'),'DD-MON-YYYY') from dual;