Filter between two dates?

How do you filter data using LINQ between two dates...

I tried this code but to no avail:

Dim dtDesde as dateTime = datepickerDesde.Value
Dim dtHasta as dateTime = DatepickerHasta.value

Dim employeeList = From Employee In TimeOneDataContext.Employees Where Employee.RecordDate >= dtDesde.ToShortDatestring And Employee.RecordDate <= dtHasta.ToShortDateString Select Employee


I checked the database and confirmed that there is a Recorddate that is between the above date?

Any idead how to filter dates in LINQ?
LVL 15
JackOfPHAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HainKurtSr. System AnalystCommented:
do you get any records when you try these
Dim employeeList = From Employee In TimeOneDataContext.Employees Select Employee

Dim employeeList = From Employee In TimeOneDataContext.Employees Where Employee.RecordDate <= dtHasta.ToShortDateString Select Employee

Dim employeeList = From Employee In TimeOneDataContext.Employees Where Employee.RecordDate >= dtDesde.ToShortDatestring Select Employee

Open in new window

0
JackOfPHAuthor Commented:
Yes, I do have...
0
HainKurtSr. System AnalystCommented:
you have? how many on each of those?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

HainKurtSr. System AnalystCommented:
maybe you should reverse these

Dim dtDesde as dateTime = datepickerDesde.Value
Dim dtHasta as dateTime = DatepickerHasta.value

are you sure  dtHasta >= dtDesde ???
0
HainKurtSr. System AnalystCommented:
maybe you should use

Dim employeeList = From Employee In TimeOneDataContext.Employees Where Employee.RecordDate <= dtDesde.ToShortDatestring And Employee.RecordDate >= dtHasta.ToShortDateString Select Employee

;) desde & hasta, what language is this?
0
JackOfPHAuthor Commented:
spanish
0
JackOfPHAuthor Commented:
how can you remove the time in the Employee.RecordDate? In the above query?
0
Jorge PaulinoIT Pro/DeveloperCommented:
Try to change the two variables to this (code snippet) and remove the ToShortDateString() method on the LINQ query.

        Dim dtDesde As DateTime = New DateTime(datepickerDesde.Value.Year, datepickerDesde.Value.Month, datepickerDesde.Value.Day, 0, 0, 0)
        Dim dtHasta As DateTime = New DateTime(DatepickerHasta.Value.Year, DatepickerHasta.Value.Month, DatepickerHasta.Value.Day, 23, 59, 59)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.