thevan
thevan

Reputation: 10354

convert string to 24 hour datetime format in mysql

I am new to mysql. I need to insert the string '2014-07-10 13:33:33' into the table column which has datetime datatype.

I gave like this,

 SELECT STR_TO_DATE('2014-07-09 23:30:00', '%Y/%m/%d %h:%m:%s');

But i didn't not give the result. How to do this?

Upvotes: 7

Views: 19129

Answers (2)

Matas Vaitkevicius
Matas Vaitkevicius

Reputation: 61401

Shouldnt it be

SELECT STR_TO_DATE('2014-07-09 23:30:00', '%Y-%m-%d %H:%i:%s');

%Y for year numeric, four digits
%m for month numeric
%d for Day of the month, numeric
%H for 24 hours
%i for minutes
%s for seconds

Upvotes: 6

Gordon Linoff
Gordon Linoff

Reputation: 1269773

Minutes is %i, not %m and 24-hour format is %H, not %h:

SELECT STR_TO_DATE('2014-07-09 23:30:00', '%Y-%m-%d %H:%i:%s');

Upvotes: 20

Related Questions