Skip to content

Instantly share code, notes, and snippets.

@r1d3rzz
Created July 12, 2024 07:37
Show Gist options
  • Save r1d3rzz/d25bedb5d5f3b67d4d4661ad384a8750 to your computer and use it in GitHub Desktop.
Save r1d3rzz/d25bedb5d5f3b67d4d4661ad384a8750 to your computer and use it in GitHub Desktop.
// Assuming employee.PermanentEndDate is DateTime? (nullable DateTime)
if (employee.PermanentEndDate.HasValue)
{
var empPermanentEndDate = employee.PermanentEndDate.Value.Date; // Use .Date to ignore the time part
var today = DateTime.Today;
var previousDay = DateTime.Today.AddDays(-1);
if (empPermanentEndDate == previousDay && previousDay == today)
{
// Do something if empPermanentEndDate is the same as yesterday and today
}
else if (empPermanentEndDate == previousDay)
{
// Do something if empPermanentEndDate is the same as yesterday but not today
}
else if (empPermanentEndDate == today)
{
// Do something if empPermanentEndDate is the same as today but not yesterday
}
else
{
// Do something if empPermanentEndDate is neither today nor yesterday
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment