1

i getting the date range from sql, i am passing the date range in linq query as below to display employee time-offs in that pay-period.

 var query = from l in leaves
                        where (l.Company == Convert.ToString(500)&&(l.StartDate >= Convert.ToDateTime(PayCheckDates[0].ToString()).Date) && (l.StartDate <= Convert.ToDateTime(PayCheckDates[1].ToString()).Date))
                        select new 
                        {
                            l.Title,
                            l.RequesterImnName,
                            l.ManagerImnName,
                            l.StartDate,
                            l.EndDate,
                            l.TotalHours,
                            l.VacationType

                        };

i am able to get the results if the start-date begins in that pay-period. lets say the PayCheckDates[0] is 2018-05-28 and PayCheckDates[1] is 2018-06-10 is person took time off from 2018-05-25 to 2018-06-05. it is not showing in that result, because the start date of that timeoff is before PayCheckDates0, if an employee took the time off before current payperiod to next payperiod, i want to show that time off in both current and next period views

  • Hi, Can you please elaborate your question? – Shridhar J Joshi May 30 '18 at 15:38
  • @Shridhar J Joshi elaborated the question – karthik May 30 '18 at 16:13
0

with this you can get the data in between dates in all cases

var query = from l in leaves
                            where (l.Company == Convert.ToString(500) && ((l.StartDate >= Convert.ToDateTime(PayCheckDates[0].ToString()).Date) && (l.StartDate <= Convert.ToDateTime(PayCheckDates[1].ToString()).Date))
                            || ((l.EndDate >= Convert.ToDateTime(PayCheckDates[0].ToString()).Date) && (l.EndDate <= Convert.ToDateTime(PayCheckDates[1].ToString()).Date)))
                            select new
                            {
                                l.Title,
                                l.RequesterImnName,
                                l.ManagerImnName,
                                l.StartDate,
                                l.EndDate,
                                l.TotalHours,
                                l.VacationType

                            };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.