Click here to Skip to main content
15,888,064 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am trying to get data between two dates.
Table name = kidsFee;
column name = fee_date; data type varchar(200)
I am trying following query



Thanks in advance

What I have tried:

SQL
SELECT * FROM kidsFee
WHERE fee_date BETWEEN '30/4/2016' AND '22/5/2016';

I ma trying this query but its not working. What should I do?
Posted
Updated 5-Jul-16 18:37pm
v2
Comments
Suvendu Shekhar Giri 5-Jul-16 8:55am    
Your query seems to be alright. Just a suggestion, use "yyyy/M/d" format like-
WHERE fee_date BETWEEN '2016/4/30' AND '2016/5/22';

Can you share some sample record you want in the result?
arvindispra 5-Jul-16 11:45am    
fine ---- ---- total -------- fee_date

20------ 2585---- 30/4/2016
10------ 1510---- 30/4/2016
10------ 1510---- 30/4/2016
10------ 1510---- 30/4/2016
45------ 435----- 30/4/2016
656----- 34545---- 30/4/2016
345----- 3453---- 30/4/2016
5------- 7256---- 30/4/2016
300----- 1620---- 22/5/2016
108----- 936----- 5/6/2016
208----- 1836---- 5/6/2016
5------- 166----- 5/6/2016
5------- 1009----- 5/6/2016
99------- 495----- 5/6/2016
9------- 45------ 5/6/2016
90------ 450----- 5/6/2016
6------- 58------ 12/6/2016
400------ 1530----- 27/6/2016

You can't perform a direct comparison between a string and a date, you need to perform a conversion first.
WHERE CONVERT(DATE, fee_date) BETWEEN CONVERT(DATE, '2016-04-30') AND CONVERT(DATE, 
'2016-05-22')

or
WHERE CONVERT(DATE, fee_date) BETWEEN '2016-04-30' AND '2016-05-22'
 
Share this answer
 
SQL
SELECT * FROM tableName  WHERE columName 
BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 5 DAY)
 
Share this answer
 
Please try .....

SELECT * FROM kidsFee
WHERE fee_date > '2016/04/30' and Date < '2016/05/22';

OR

SELECT * FROM kidsFee
WHERE fee_date BETWEEN '04/30/2016' AND '05/22/2016';
 
Share this answer
 
Comments
Marcus Kramer 5-Jul-16 16:46pm    
Won't work if his fee_date column is a varchar(200)
barneyman 5-Jul-16 19:49pm    
why on earth are you storing dates as strings?

ok - so you're going to have to CONVERT each row datestring into a DATE and the min/max datestrings also into DATEs
SELECT * FROM kidsFee
WHERE fee_date BETWEEN '2016-04-30' AND '2016-05-22'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900