Lawrence Pond

Lawrence Pond

  • NA
  • 164
  • 0

Linq datetime use only the date portion to compare list

Oct 23 2014 8:10 PM

The following code, has two lists of dates one is a list of course date (courseDateList)  the other is the selected dates (selectedDateList). I want to find the dates that are in the courseDateList  but are not in  the selectedDateList.

Compare only the date portion not the time of the selectedDateList or courseDateList

So the expected output should be:
5/7/2014 7:00:00 AM
5/7/2014 12:00:00 PM



void Main()
{
var courseDateList = new[]
{
new Dates { Start= Convert.ToDateTime("05/05/2014 07:00:00 AM")},
new Dates { Start= Convert.ToDateTime("05/05/2014 12:00:00 PM")},
new Dates { Start = Convert.ToDateTime("05/06/2014 07:00:00 AM")},
new Dates { Start = Convert.ToDateTime("05/06/2014 12:00:00 PM")},
new Dates { Start= Convert.ToDateTime("05/07/2014 07:00:00 AM")},
new Dates { Start= Convert.ToDateTime("05/07/2014 12:00:00 PM")}
     };

 var selectedDateList = new[]
{
new Dates { Start= Convert.ToDateTime("05/05/2014 08:00:00 AM")},
new Dates { Start= Convert.ToDateTime("05/06/2014 05:00:00 PM")}
     };
 
selectedDateList.Dump();
courseDateList.Dump();
}


public class Dates
{
    public DateTime Start {get; set;}
}


Answers (3)