• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

checking for day of week in asp.net

How would I write this if statement in asp.net?
i need a check to see if the day of the week is not Friday or saturday in VB.net
<% if WeekdayName(weekday(date)) <> "Friday" and WeekdayName(weekday(date)) <> "Saturday" then %>
1 Solution
It's better to use DayOfWeek. See here for details: http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek(v=vs.110).aspx

It would be something like:

<% if date.DayOfWeek <> DayOfWeek.Friday and date.DateOfWeek <> DayOfWeek.Saturday then %>
If Weekday(Date) = vbSaturday Or Weekday(Date) = vbSunday Then
rivkamakAuthor Commented:
I got the following errors on both of yours
@: jss1199: C32093: 'Of' required when specifying type arguments for a generic type or method.
@TheAvenger:BC30469: Reference to a non-shared member requires an object reference.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
please use this

rivkamakAuthor Commented:
so what is wrong with this?
'if  System.DateTime.Now.DayOfWeek  = "Saturday"   Or System.DateTime.Now.DayOfWeek <> "Friday" Then
error: System.FormatException: Input string was not in a correct format.
Craig WagnerSoftware ArchitectCommented:
If you look up the documentation for DayOfWeek (http://msdn.microsoft.com/en-us/library/system.datetime.dayofweek(v=vs.110).aspx) (instead of making others do your job for you) you'll see that it returns an enum, not a string.

DateTime.Now.DayOfWeek = DayOfWeek.Saturday
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now