2

I have the date in this format in mySQL databse:

2011-02-21 14:40:03

But i have to compare only datepart of this dateandtime i.e:

2011-02-21

How???

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
Shahid Karimi
  • 4,096
  • 17
  • 62
  • 104

2 Answers2

4

A better solution is to use WHERE col >= '2011-02-21' AND col < '2011-02-22', so MySql can use a index if there is one present.

The Scrum Meister
  • 29,681
  • 8
  • 66
  • 64
  • Yes, because everybody should [write queries for continuous periods as explicit range condition](http://use-the-index-luke.com/sql/where-clause/obfuscation/dates). – Markus Winand Mar 08 '11 at 06:55
3
... where date(datetime_column) = '2011-02-21'

Here is the documentation

Sarwar Erfan
  • 18,034
  • 5
  • 46
  • 57