How to compare with a list of dates in C #?

I have two date lists. I need to compare both lists and find the missing date. My first list is as follows:

2015-07-21 2015-07-22 2015-07-23 2015-07-24 2015-07-25 2015-07-26 2015-07-27 

My second list looks like

 2015-07-21 2015-07-22 2015-07-23 2015-07-25 2015-07-26 2015-07-27 

I need to find a missing date between two lists:

I tried this

 var anyOfthem = firstList.Except(secondList); 

But that did not work. Can anyone help me with this?

+7
date list c # datetime except
source share
4 answers

It looks like you can use .Except() .Union() methods:

  string[] array1 = { "2015-07-21", "2015-07-22", "2015-07-23", "2015-07-24", "2015-07-25", "2015-07-26", }; string[] array2 = { "2015-07-21", "2015-07-22", "2015-07-23", "2015-07-25", "2015-07-26", "2015-07-27" }; var result = array1.Except(array2).Union(array2.Except(array1)); foreach (var item in result) Console.WriteLine(item); 

Result: "2015-07-24", "2015-07-27",

+10
source share
 string[] array1 = { "2015-07-21", "2015-07-22", "2015-07-23", "2015-07-24", "2015-07-25", "2015-07-26", }; string[] array2 = { "2015-07-21", "2015-07-22", "2015-07-23", "2015-07-25", "2015-07-26", "2015-07-27" }; var common = list1.Intersect(list2); var anyOfThem = list1.Except(common).Concat(list2.Except(common)); foreach (var date in anyOfThem) Console.WriteLine(date); // 2015-07-24 // 2015-07-27 
+3
source share

You need to check if one list contains values โ€‹โ€‹from another list:

 var anyOfthem = firstList.Where(x => !secondList.Contains(x)); 
0
source share

Hope this is exactly what you are looking for:

 var notamatch= firstList.Where(x => !anyOfthem.Any(y => y.yourseconddatename== x.yourfirstdatename)); 
0
source share

All Articles