wrexham2008
New Member
so using LINQ attempting to compare 2 values in the DB and select where the date is less than exactly a year today...so anything between 24/1/12 & 24/1/13 will be selected.So i've got...\[code\] var selectedObject = (from workstation in db.Work_Station join invoice in db.Invoices on workstation.id equals invoice.Site_Id where InvoiceDate < DateTime.Now.AddYears(-1) select workstation).Distinct().ToList();\[/code\]this is producing a list but its not correct.I've been playing about with the add years but can't seem to get it..Anyone have any ideas?Thank YouEDIT:Hey everyone thank you for the quick response...i actually made a slight mistake, I want to return the value which has an invoice date of greater than exactly a year today.....So anything dated <= 24/1/12 will be returned. i have used ur suggestions to use...DateTime OneYearAgo = DateTime.Now.AddYears(-1);\[code\] var selectedObject = (from workstation in db.Work_Station join invoice in db.Invoices on workstation.id equals invoice.Site_Id where InvoiceDate <= OneYearAgo select workstation).Distinct().ToList();\[/code\]This returns a number of invoices...some of which are before the 23/1/12 and some of which are after.Iv tried changing to where CurrentInvoiceDate >= OneYearAgo, which should return any dated between now and one year ago, but nothing is returned...what am i doing wrong? please advise...thank you