I want to check if a given date is more than a month earlier than today's date using LINQ.
What is the syntax for this?
Thanks in advance.
I want to check if a given date is more than a month earlier than today's date using LINQ.
What is the syntax for this?
Thanks in advance.
I assume that you're talking about in the where clause. It's basically the same way you would compare two DateTime objects elsewhere.
using (DataContext context = new DataContext()) {
var query = from t in context.table
where t.CreateDate.Date < DateTime.Today.AddMonths(-1)
select t;
}
var data = (from x in _context.tblAttendance
where (x.intime.Date >= frmDate.Date & x.intime.Date <= toDate.Date)
//where ((x.intime.Day >= frmDate.Day || x.intime.Day <= toDate.Day) &
//(x.intime.Month >= frmDate.Month || x.intime.Month <= toDate.Month) &
//(x.intime.Year >= frmDate.Year || x.intime.Year <= toDate.Year)) &
//(userID.Equals(0) || x.tblEmployee.id == userID)
select new
{
Breaks = x.tblBreakInfo,
Attendance = x,
Employee = x.tblEmployee
}).ToList();
sorry your code of comparing the dates not working with my case...
any help on that...i'm working in 2008
and the exception is given as below..
The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.