简体   繁体   中英

Query returns null for data from current day to upcoming 7 days

I have got this table and data as shown below

CREATE TABLE events_calender (
  company_name varchar(30) DEFAULT NULL,
  reg_date varchar(20) 
);

Insert into events_calender values('Childerse Event' , '30-Oct-2015');
Insert into events_calender values('Womens Event' , '05-Nov-2015');
Insert into events_calender values('Mens Event' , '02-Nov-2015');
Insert into events_calender values('DOlls Event' , '02-Oct-2015');

I want to return data from current day to upto Upcoming 7 days (Upcoming events)

I have tried it this way

SELECT * from events_calender WHERE reg_date BETWEEN DATE( NOW() ) AND DATE( DATE_ADD( NOW() , INTERVAL 7 DAY ) )

But no data is actually returned even though the records are present

http://sqlfiddle.com/#!9/25bd0/3

Wrong type declared reg_date varchar(20) should be reg_date date :

http://sqlfiddle.com/#!9/22cfe/1

CREATE TABLE events_calender (
  company_name varchar(30) DEFAULT NULL,
  reg_date date 
);

Insert into events_calender values('Childerse Event' , '2015-10-30');
Insert into events_calender values('Womens Event' , '2015-11-05');
Insert into events_calender values('Mens Event' , '2015-11-02');
Insert into events_calender values('DOlls Event' , '2015-10-02');

SELECT * 
FROM events_calender 
WHERE reg_date BETWEEN DATE( NOW() ) AND DATE( DATE_ADD( NOW() , INTERVAL 7 DAY ) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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