views:

26

answers:

1

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?

+4  A: 

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.

OMG Ponies
Ah, I must've been using outdated documentation... thanks a bunch!
Matt