Monday, 13 July 2009

Using date format from Toad for MySQL

By default in my locale (UK) Toad for MySQL displays this date format for 9:30ish on July 10.

'10/07/2009 09:30:48'

However, if I try to use that format in a SQL command in the editor, for example

SELECT * FROM foo WHERE changed = '10/07/2009 09:30:48'

I get this error

Commands out of sync; You can't run this command now

The default date format is 'YYYY-MM-DD HH:MM:SS' so I could do

SELECT * FROM foo WHERE changed = '2009/07/10 09:30:48'

or use STR_TO_DATE and do

SELECT * FROM foo WHERE changed = STR_TO_DATE('10/07/2009 09:30:48','%d/%m/%Y %H:%i:%s');

No comments:

Post a Comment