Nilesh patel Nilesh patel - 4 months ago 11
SQL Question

Get time from Timestamp stored as varchar

I have timestamps in

varchar(20)
like
'01-11-2012 11:36:53.122'


If I get only date by

SELECT STR_TO_DATE("01-11-2012 11:36:53.122", '%d-%m-%Y')


it gives this output:
"2012-11-01"
.

But by this

SELECT STR_TO_DATE("01-11-2012 11:36:53.122", '%H:%i:%s')


it gives the output
"null"
instead of
11:36:53
.

What is query to get only the time?

Answer

give this a try

DATE_FORMAT(STR_TO_DATE(`column`, '%d-%m-%Y %H:%i:%s'), '%H:%i:%s')

Other sources,

Comments