0

Sorry about the generic title, I didn't know how to phrase this.

I have a DateTime in my MySQL DB. For example: 14/06/2016 15:01:00

When I try to do a query to find dates which equal certain dates it won't find anything, unless I used the Americanised date format. Yet it's stored in the English way.

Eg:

Select * FROM tbl WHERE Date = '14/06/2016' - Doesn't return any results

But Select * FROM tbl WHERE Date = '2016/06/14' does return results.

Why is this? And how can I swap it around?

Andrew Kilburn
  • 2,251
  • 6
  • 33
  • 65

1 Answers1

2

http://dev.mysql.com/doc/refman/5.7/en/datetime.html

The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

If you're seeing a different format, your SQL client is "helpfully" changing the output from the underlying data storage.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • Okay, so to perform a query on the date time I have to use the 'YYYY-MM-DD' format? – Andrew Kilburn Jun 15 '16 at 15:14
  • @AndrewKilburn Yes, you should. It looks like it's correctly interpreting your `YYYY/MM/DD` but you shouldn't count on that - for best results, use the format MySQL expects. – ceejayoz Jun 15 '16 at 15:16