R Ban
R Ban

Reputation: 97

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.

Upvotes: 0

Views: 3615

Answers (1)

Koushik Roy
Koushik Roy

Reputation: 7407

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.

Upvotes: 2

Related Questions