Link to home
Start Free TrialLog in
Avatar of dan henderson
dan hendersonFlag for United States of America

asked on

use linq to get a record between two times

I have a record in sql server 2016 that has two time(0) columns.  I need to do a query with linq that returns the id when the current time is between the 2 stored times (starttime and endtime).

any help appreciated.

string now = DateTime.Now.ToString("HH:mm:ss");

            var result = (from s in db.Shifts
                          where s.StartTime >= DateTime.Parse(now) &&
                          s.EndTime <= DateTime.Parse(now)
                          select s.ShiftId);

Open in new window

Avatar of PortletPaul
PortletPaul
Flag of Australia image

Only "time" columns; no "date" column or columns?
do any shift cross-over midnight?
Can you provide sample data?
ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial