简体   繁体   English

从添加日期起选择n天以内的日期

[英]Select date with n days from the date added

I have a mysql table with the following fields 我有一个具有以下字段的mysql表

Name | Email | Date | Status

I want to extract the records where date range is between 30 days 我想提取日期范围在30天之间的记录

Assume today is 2014/12/9 假设今天是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) 我需要o / p为(从数据库日期到今天的30天之内的天数)

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. 我想提取那些从数据库中的日期间隔少于30天的记录。

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? 如何编写选择查询?

USE DATE_SUB like this: 像这样使用DATE_SUB

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

Working Fiddle Demo: http://sqlfiddle.com/#!2/6344f2/1 工作小提琴演示: http ://sqlfiddle.com/#!2/6344f2/1

use following query 使用以下查询

select * from table_Name t where t.date<=now() and t.date>=DATE_SUB(now(),
INTERVAL 31 DAY)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM