>Can not yet make it to work. That's my latest attempt which blows up in run-time:
>
>
> var startTime = new DateTime(1900, 1, 1, beginDateTime.Hour, beginDateTime.Minute, 0);
> var endTime = new DateTime(1900, 1, 1, endDateTime.Hour, endDateTime.Minute, 0);
> var daysOfWeek = dailyLimits.Where(dl => dl.Selected == true).Select(ds => ds.WeekDay).ToList();
> if (daysOfWeek.Count() < 7) // not all days of the week selected
> {
> query = query.Where(m4s => DateTime.Parse("01-01-1900 " + m4s.StartTime.Value.ToShortTimeString()) <= endTime &&
> DateTime.Parse("01-01-1900 " + m4s.EndTime.Value.ToShortTimeString()) >= startTime && daysOfWeek.Contains((short)m4s.StartTime.Value.DayOfWeek));
> }
>
>about the Parse problem. Has anyone deal with this problem already of getting time portion of the date using LINQ?
>
>Thanks in advance.
>
>UPDATE. Tried TimeOfDay and it worked in my quick test, but the code it produced is not a clear conversion to time as I hoped. Still looking for better solutions.
Don't use DateTime.Parse to add a date and time. Its a needless conversion and subject to regional settings. Create a DateTime object set to 1/1/1900 to use as your starting point. Add the StartTime or EndTime's TimeOfDay to your 1/1/1900 object's Date property to get the DateTime you are looking for.