Solved

checking for day of week in asp.net

Posted on 2013-12-12
8
373 Views
Last Modified: 2013-12-30
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 %>
0
Comment
Question by:rivkamak
8 Comments
 
LVL 20

Expert Comment

by:TheAvenger
ID: 39714979
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 %>
0
 
LVL 19

Expert Comment

by:jss1199
ID: 39714984
If Weekday(Date) = vbSaturday Or Weekday(Date) = vbSunday Then
0
 

Author Comment

by:rivkamak
ID: 39715789
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.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 39716125
hi...
please use this

System.DateTime.Now.DayOfWeek
0
 

Author Comment

by:rivkamak
ID: 39717379
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.
0
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 280 total points
ID: 39726758
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
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question