7

I have two list of date. I have to compare both list and find missing date. My first list looks like this:

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 this

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

I have to find the missing date between the two list :

I tried this

var anyOfthem = firstList.Except(secondList);

But it didn't work. Can anyone help me with this ?

Priya
  • 591
  • 1
  • 8
  • 23

4 Answers4

9

Well, you could use .Except() and .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);
        }

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

Fabjan
  • 13,506
  • 4
  • 25
  • 52
3
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
w.b
  • 11,026
  • 5
  • 30
  • 49
0

You have to check if one list contains the values from the other list :

var anyOfthem = firstList.Where(x => !secondList.Contains(x));
thomasb
  • 5,816
  • 10
  • 57
  • 92
MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
0

hope this is exactly what your looking for:

var notamatch= firstList.Where(x => !anyOfthem.Any(y => y.yourseconddatename== x.yourfirstdatename));
DeshDeep Singh
  • 1,817
  • 2
  • 23
  • 43