SolvedPrivate

using linq in C# to get DateTime range from list

Posted on 2014-09-17
3
38 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
  • 2
3 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
turnsout the data received was incorrect - thanks for the reply.
0
 

Author Closing Comment

by:bojeff30
Comment Utility
issue due to bad data
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now