سؤال

I'm running into a problem with MySQL's STR_TO_DATE function. For example, this code:

SELECT STR_TO_DATE("Saturday October 23 2010 11:00 AM", "%W %M %d %Y %h:%m %p");

outputs this:

2010-00-23 11:00:00

Why is everything correct except the month? Is this an error in my syntax?

هل كانت مفيدة؟

المحلول

You're using the wrong modifier for minutes - use:

SELECT STR_TO_DATE("Saturday October 23 2010 11:00 AM", "%W %M %d %Y %h:%i %p")

You specified %m, which was overwriting the %M value - see the modifiers via the DATE_FORMAT documentation. That's why the month was coming out as zero - the modifier for minutes is %i.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top