How to find if any day in calendar year is weekend or not


#1

Hi,

How do we find if any day in calendar year is a weekend or not.
I checked other thread but all solution were specific to current day using now.DayofWeek.ToString().

Let’s say with some calculation my resultant date is 2nd Feb 2019. Now how to check if this is weekend or not.

Thanks in advance.


#2

Let’s say the date you have is 02-02-2019.

If you have a valid date string(“02-02-2019”) and not a DateTime object, convert it to a DateTime object first (You can use DateTime.Parse(“02-02-2019”) or Convert.ToDateTime(“02-02-2019”), and store it in a variable (say dtDate)).

Now, once you have the date as a DateTime object, the following shall do the trick for you:
dtDate.DayOfWeek.ToString.

What’s next is to check if it’s equal to a “Saturday” or a “Sunday”. That’s it. Try it and let me know if it worked.

-SG


#3

See this sample -

Main.xaml (7.1 KB)


#4

Thanks Siddharth… It worked :slight_smile:


#5

great :slight_smile: Thanks Prankurjoshi … worked perfectly .