• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 821
  • Last Modified:

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?
0
JackOfPH
Asked:
JackOfPH
  • 4
  • 3
2 Solutions
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now