-2

IN() operator uses the exact match of values in paranthesis . I want to fetch record from db like in operator with respect to date. in db there are date assigned to each record? how this can be done.

Dharman
  • 30,962
  • 25
  • 85
  • 135
pran
  • 29
  • 1
  • 7
  • 1
    possible duplicate of [Comparing date ranges](http://stackoverflow.com/questions/143552/comparing-date-ranges) – Chad Nouis Jul 07 '15 at 13:41
  • it is not duplicate,if you have answer pls share – pran Jul 07 '15 at 13:52
  • Your question is very short, hence it is hard to understand what you want. We can only guess with this little information. Please show some sample data as input and what you expect as output. What have you tried so far? – René Hoffmann Jul 07 '15 at 15:26

2 Answers2

0

IN works with dates as well as all other types (although you should not use it with floating point values):

where dte in ('2015-01-01', '2014-01-01', '2013-01-01')

However, for the last "n" days, you would just use:

where dte > date_sub(curdate(), interval 2 day)

Or whatever logic you want.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • ,this will not solve problem,I want query like SELECT * FROM df_register_users WHERE date(CREATED) > DATE_SUB(NOW(), INTERVAL 7 DAY) ORDER BY `CREATED` DESC b – pran Jul 07 '15 at 13:42
  • But this query,will select record of only last 7 days,how multiple days can be used – pran Jul 07 '15 at 13:43
  • @pran . . . Change the interval to whatever value you want. – Gordon Linoff Jul 08 '15 at 02:41
0

I think you should be using WHERE yourdate BETWEEN start AND finish if I have understood you correctly.

If you need 2 days and 3 days and fifteen days then a UNION is a method I have used recently to achieve similar.

However it depends on the output you are looking for

logbook
  • 45
  • 1
  • 5
  • Output i expect , is very basic,there are number of record with date in db ,which are 2 day before now,3 day before now,5 before now etc – pran Jul 07 '15 at 13:49