learningtech
learningtech

Reputation: 33683

my str_to_date in mysql is returning null

I ran this statement in mysql and it returns null on every row:

SELECT STR_TO_DATE('Fri, 22 Jun 2012 03:35:24 +0000', '%a, %e %b %Y %H:%i:%s %%%%%%%%%%') FROm t2;

I don't know the right specifier for the +0000. What should it be?

Upvotes: 2

Views: 1263

Answers (1)

Pekka
Pekka

Reputation: 449385

The +0000 is a time zone offset.

mySQL doesn't understand the concept of time zones, and apparently neither does STR_TO_DATE: the list of date/time format placeholders doesn't mention time zones at all.

If you expect dates from varying time zones, this doesn't seem solvable with the help of mySQL only. You would have to preprocess the date elsewhere to turn it into one that is always UTC (or your local time zone, whatever applies), or if it already is always UTC, ManseUK's suggestion (adding +0000 to your format string so mySQL ignores it) should work.

Upvotes: 3

Related Questions