0

I have a table like this: enter image description here

I want to to do something like this:

select * from stat_tps Where min_date ='2013-06-12'

but the problem as you see the min_date is datetime format, so I have to provide the hh:mm:s part. I was wondering if there is any way that I can apply my query without specifying the hours-minutes and seconds?

thanks..

tkyass
  • 2,968
  • 8
  • 38
  • 57

4 Answers4

3
select * from stat_tps
Where date(min_date) = '2013-06-12'

But that won't take use of indexes if you have one on the min_date column. Better use

select * from stat_tps
Where min_date >= '2013-06-12'
and min_date < '2013-06-13'
juergen d
  • 201,996
  • 37
  • 293
  • 362
2

Use the DATE() function:

SELECT * FROM stat_tps WHERE DATE(min_date) ='2013-06-12'
PinnyM
  • 35,165
  • 3
  • 73
  • 81
-1

You need to specify a range, this will effecitvely use an index.

select * from stat_tps 
Where min_date BETWEEN '2013-06-12' AND DATE_ADD('2013-06-12',INTERVAL 1 DAY)
jishi
  • 24,126
  • 6
  • 49
  • 75
-2

Use the SUBSTR function to chop off the time.

PP.
  • 10,764
  • 7
  • 45
  • 59
  • `select * from stat_tps Where SUBSTR(min_date,0,10) = '2013-06-12'` – PP. Jul 12 '13 at 14:39
  • 1
    I used the query you provided and its working perfect, but I had one problem and I wanted to put it here for others to benefit from it when using your answer... setting the length to zero didnt return anything so instead I set the length to 1 and it returned the desired results. ` select * from stat_tps where substring(min_date,1,10)='2013-06-14' ` – tkyass Jul 12 '13 at 14:48
  • Yes, you're right, the [MYSQL documentation for SUBSTR](http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_substr) specifies that the first character of the string is at position 1. – PP. Jul 12 '13 at 14:50