-1

I want to using lambda expression to compare current DateTime.Now with time retrieved from database (time).

I try this:

string time = DateTime.Now.Hour.ToString("00") + DateTime.Now.Minute.ToString("00") + DateTime.Now.Second.ToString("00");
TimeSpan _currentTime = TimeSpan.ParseExact(time, "HHmmss", CultureInfo.InvariantCulture);

IQueryable<user> Query = _context.user.Where(s => s.userShifts.Any(s2 => s2.DayOfWeekId == _todayNumber && _currentTime >= s2.TimeFrom && _currentTime <= s2.TimeTo));

I got the following error:

{"Input string was not in a correct format."}

What's the wrong !!

Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66

2 Answers2

1

Use TimeOfDay in place of parseExact

var _currentTime= DateTime.Now.TimeOfDay
Danny D
  • 828
  • 1
  • 9
  • 20
0

Ok .. The right format is:

TimeSpan _currentTime = TimeSpan.ParseExact(time, "hh':'mm':'ss", null);

Hope this help.

Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66