?
SolvedPrivate

using linq in C# to get DateTime range from list

Posted on 2014-09-17
3
Medium Priority
?
59 Views
Last Modified: 2016-02-15
I am using linq(in c#) to get the records going back 1 year back. My code below works if i use .AddMonths(-10);  but if I used AddMonths(-12); all the records are returned. I'm not sure why this occurs.  

Could someone tell how can i get the previous 12 month using linq.  




                  var result = items
                    .Where(x => !x.IsDeleted)
                    .OrderByDescending(x => x.OpenedAt)                  
                    .Take(perPage)
                    .ToList();




                var startDate1 = DateTime.Now.AddMonths(-10);              
                var newResult1 = result.Where(x => x.CreatedAt >= startDate1);


                var startDate2 = DateTime.Now.AddMonths(-12);              
                var newResult2 = result.Where(x => x.CreatedAt >= startDate2);
0
Comment
Question by:bojeff30
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40330983
What are the values of x.CreatedAt that are not evaluating correctly, can you post some examples?
0
 

Accepted Solution

by:
bojeff30 earned 0 total points
ID: 40333112
turnsout the data received was incorrect - thanks for the reply.
0
 

Author Closing Comment

by:bojeff30
ID: 40348356
issue due to bad data
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question