1

I have a mysql table with the following fields

Name | Email | Date | Status

I want to extract the records where date range is between 30 days

Assume today is 2014/12/9

ie. date values are

2014/11/25 

2014/12/2

2014/12/1

2014/10/25

2014/11/9

I need the o/p as (the number of days should be with in 30 days from the db date to today date)

2014/11/25 

2014/12/2

2014/12/1

2014/11/9

I want to extract records those have the interval of less than 30 days from the date in the db.

Yes. I want to fetch the record between 2 days. For this I used this query

SELECT * FROM tbl_jobboard WHERE dtDate <= ( dtDate +30 ) 

But it is not working.

How to write the select query?

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
Sam Hanson
  • 1,317
  • 4
  • 22
  • 48
  • possible duplicate of [Select data from date range between two dates](http://stackoverflow.com/questions/14208958/select-data-from-date-range-between-two-dates) – Joel Brewer Dec 09 '14 at 05:53
  • Yes. I want to fetch the record between 2 days. For this I used this query SELECT * FROM `tbl_jobboard` WHERE `dtDate` <= ( dtDate +30 ) . But it is not working. – Sam Hanson Dec 09 '14 at 06:02

2 Answers2

1

USE DATE_SUB like this:

SELECT * FROM table1
WHERE `date` BETWEEN DATE_SUB(CURDATE(),INTERVAL 30 DAY) AND CURDATE()

Working Fiddle Demo: http://sqlfiddle.com/#!2/6344f2/1

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
0

use following query

select * from table_Name t where t.date<=now() and t.date>=DATE_SUB(now(),
INTERVAL 31 DAY)
Fathah Rehman P
  • 8,401
  • 4
  • 40
  • 42