Reputation: 750
Goal:
Searching between two selected date by datepickers.
Inserted dates format :
DateTime.Now()
result is: 2/23/2021 5:18:04 PM
Linq query :
var list = from d in ctx.SellInvoices
where d.Date >= dtpStartDate.SelectedDate.Value
&& d.Date <= dtpEndDate.SelectedDate.Value
select d;
Problem :
if dtpEndDate selected date is tommorow (2/24/2021) it returned result, but if i select today not returned any thing. what is problem here?
Addition:
if saved date as DateTime.Today()
result is 2/23/2021 12:00:00 AM and search query returned good but for 12:00:01 AM should selecting one day later. Here I don't want to save with DateTime.Today().
Upvotes: 0
Views: 266
Reputation: 11
If you have set dtpEndDate as just 2/23/2021 (today) it will actually be 2/23/2021 00:00:00
So when you compare d.Date <= dtpEndDate.SelectedDate.Value
It will be 2/23/2021 5:18:04 PM <= 2/23/2021 00:00:00.
Upvotes: 1