Zion Saal
Zion Saal

Reputation: 55

C# how to check if DateTime Object value is someday

C# how to check if DateTime Object value is someday

 public static string GetBalance(DateTime date)
    {
if (date = 3/23/2021 || date = 3/22/2021)
{
do somthing
}
    }

Upvotes: 0

Views: 142

Answers (2)

Zion Saal
Zion Saal

Reputation: 55

this worked for me

if (date == DateTime.Parse("2021-03-22") || date == DateTime.Parse("2021-03-23"))

Upvotes: 0

Yong Shun
Yong Shun

Reputation: 51160

To compare two dates without time:

public static string GetBalance(DateTime date)
{
    DateTime firstDateToCompare = new DateTime(2021, 3, 22);
    DateTime secondDateToCompare = new DateTime(2021, 3, 23);
    if (date.Date == firstDateToCompare.Date || date.Date == secondDateToCompare.Date)
    {
        //do something
    }
}

Upvotes: 1

Related Questions