Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Experts..

I am new in crystal Report development. I want to know that how to get the data from between two dates. I am having Two Textboxes for from date and To date in a FrmDate(Form). and put one button for clicke event. if i am give the two different date into two texbox and then click that button my report showing the data between that dates only. kindly help to me..
DB is sqlserver2005
Thanks in Advance.
Sreeni
Posted
Updated 5-Sep-19 20:45pm

Select * from
TableName t
WHERE CONVERT(Date,t.Fromdate,10) >= CONVERT(Date,@FromDate,10)
and
CONVERT(Date,t.ToDate,10) <= CONVERT(Date,@ToDate,10)

Please accept this solution if its fulfill your needs
 
Share this answer
 
Comments
sreenivashan 25-Aug-14 7:28am    
Hi Rahul.. This is my Question.
I am new in crystal Report development. I want to know that how to get the data from between two dates. I am having Two Textboxes for from date and To date in a FrmDate(Form). and put one button for clicke event. if i am give the two different date into two texbox and then click that button my report showing the data between that dates only. kindly help to me..
DB is sqlserver2005
Thanks in Advance.
Sreeni
RAHUL(10217975) 25-Aug-14 9:26am    
Wat's the problem? Try What I have written
First off, don't use text boxes: use a Calendar control or a DateTimePicker instead. Textboxes mean that users enter what they want, which may not be a valid date (or even close to a valid date). The otehr controls only let them select "proper" dates, and save you having to validate them.

Then, just use an SQL SELECT:
SQL
SELECT * FROM MyTable WHERE MyDateColumn BETWEEN @StartDate AND @EndDate
Fill in the dates via a parametrised query, and pass the DateTime objects from the controls directly.
 
Share this answer
 
Comments
sreenivashan 25-Aug-14 7:29am    
Hi.. ok i am not use text box for dates. and use the datepicker, but my question is : I am new in crystal Report development. I want to know that how to get the data from between two dates. I am having Two Textboxes for from date and To date in a FrmDate(Form). and put one button for clicke event. if i am give the two different date into two texbox and then click that button my report showing the data between that dates only. kindly help to me..
DB is sqlserver2005
Thanks in Advance.
Sreeni
OriginalGriff 25-Aug-14 8:27am    
Read what I said?
select * from MyTable where DATE BETWEEN '" + Convert.ToDateTime(TXT_FROM_DATE.Text).ToString("MMM/dd/yyyy") + "' AND '" + Convert.ToDateTime(TXT_TO_DATE.Text).ToString("MMM/dd/yyyy") + "'
 
Share this answer
 
Comments
CHill60 6-Sep-19 3:40am    
Reasons for my downvote:
1 - this is no different to Solution 2 posted 5 years ago
2 - You are using Convert.ToDateTime which will throw an exception if the text is not in the correct format
3 - Your code is vulnerable to SQL Injection attack - never concatenate strings to create SQL statements - especially if they use data direct from user input.

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