Skip to content
Advertisement

Impala convert string to timestamp always returns to NULL

I want to convert dd/mm/yyyy hh:mm:ss string to date format.

select to_timestamp('19/05/2010 20:03:55', 'dd/mm/yyyy hh:mm:ss');

this is not converting the string to timeformat and always returns me NULL.

Please guide where I am going wrong.

Advertisement

Answer

You need to use correct format.

 select to_timestamp('19/05/2010 20:03:55', 'dd/MM/yyyy HH:mm:ss') as ts;

Output
The pattern string supports the following subset of Java SimpleDateFormat.

Pattern Description
y       Year
M       Month
d       Day
H       Hour
m       Minute
s       Second
S       Fractional second

A date string including all fields could be ‘yyyy-MM-dd HH:mm:ss.SSSSSS’, ‘dd/MM/yyyy HH:mm:ss.SSSSSS’, ‘MMM dd, yyyy HH.mm.ss (SSSSSS)’ or other combinations of placeholders and separator characters.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement