0

In MySQL trying to convert string to date time format, but its returning the null value.

What it the correct way to convert below string to datetime format?

> select STR_TO_DATE('8/16/18 7:00 PM', '%c/%e/%Y %r');
+-------------------------------------------------+
| STR_TO_DATE('8/16/18 7:00 PM', '%c/%e/%Y %r')   |
+-------------------------------------------------+
| NULL                                            |
+-------------------------------------------------+

Thanks

1 Answer 1

1

You gotta match the format, %r doesn't match 7:00 PM

From: https://www.w3schools.com/sql/func_mysql_str_to_date.asp

%r = Time in 12 hour AM or PM format (hh:mm:ss AM/PM)

As you can see, expects a two digit hour, and seconds, which you don't have.

You also don't match the year %Y expects a four digit Year... so i changed it to %y

Try like this.

select STR_TO_DATE('8/16/18 7:00 PM', '%c/%e/%y %l:%i %p');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.