How to get data in between two date
i get data from sql server in between two days using stored producer
but when i enter date is same then my data not come
problem is how to get data between two date and same date
my query is
select * from save_master where date between @fromdate AND @todate
now the date is 1/2/2009 and 3/2/2009
i got data
but the date is same data not come because user wants data only one date then we also get data
please help me in sql queary



naura paxRank #2,843 · 502 reputationPosted Oct 29, 2009, 3:21 AM EDT
I hope i understood right and you mean when fromdate='1/7/2009' and todate is also '1/7/2009' you don't get anything.
That maybe because in your date field in table you might be storing time component as well : '2009-07-01 12:15:15.349' or something like that.
one solution is to pass todate from datepicker as follows:
todate=dtpTo.Value.Date.AddDays(1).AddSeconds(-1);
and fromdate=dtpFrom.Value.Date; then pass these two variables.
try it and tell me.
Nilanka DharmadasaRank #1,875 · 794 reputationPosted Oct 29, 2009, 4:09 AM EDT
Change your query like below.
select * from save_master where date between @fromdate AND @todate + .99999
Danatas GerviRank #4,152 · 361 reputationPosted Oct 29, 2009, 5:02 AM EDT
I think, this (+0.9999) is a trick.
Better to go that way:
set @FromDate = convert(datetime,'20090708',112)
set @ToDate = convert(datetime,'20091108',112)
print @FromDate
print @ToDate
SELECT IsNull
(
(SELECT CreateDate FROM tblItem WHERE (CreateDate BETWEEN @FromDate AND @ToDate)
),
@FromDate) as RESULT
Danatas GerviRank #4,152 · 361 reputationPosted Oct 29, 2009, 5:05 AM EDT
print @FromDate ***
print @ToDate ***
*** - this is not nesessary, but it sign, that I have checked the query.
:-)
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 29, 2009, 5:23 AM EDT
select * from Orders where OrderDate between '8/1/1996' and '8/1/1996'
Danatas GerviRank #4,152 · 361 reputationPosted Oct 29, 2009, 7:54 AM EDT
As I understand, author wants to get something else, than null…..
Dharmesh SharmaRank #1,974 · 741 reputationPosted Oct 29, 2009, 9:28 PM EDT
but my problem is stil
because i have enter two date from and to date but problem is sql command not get data
what can i do
change in codeing or sql
in coding only send date without time
or
convert datetime to only in date
ti is somthing like that how it is this
and your quary not working
this selece * from Order where orderdate Between '1/7/2009' AND '1/7/2009'
not worked in sql understan
this is my problem
may be time problem i use datetimepicker so date inclued the time also that have the problem in sql or only date send to sql then sql not find data
some idea help me
Dharmesh SharmaRank #1,974 · 741 reputationPosted Oct 29, 2009, 10:02 PM EDT
i got my solution
and thanks to all
but i got self my best solution and u know about the between function
and sql query is
i convert sql field or our variable also
thanks
naura paxRank #2,843 · 502 reputationPosted Oct 30, 2009, 12:16 AM EDT
I think best option is not to store time component in your datetime field at all.
Anwarul Haque150 reputationPosted Dec 11, 2009, 2:51 AM EST
selece * from tblOrder where orderdate <='1/7/2009' AND orderdate >= '1/7/2009'
no need to put time too.
Jiyaul MustaphaRank #5,573 · 294 reputationPosted Jul 26, 2019, 4:00 AM EDT