KB-33842: Retrieving the current day of the week via scripts.

Question:

How can I tell whether the current day is a Saturday or a Sunday?

Solution:

To do so, you must use VBScript‘s Weekday function. This function returns a number that corresponds to the current day of the week: 1 for Sunday, 2 for Monday, 3 for Tuesday, 4 for Wednesday, 5 for Thursday, 6 for Friday, and 7 for Saturday. With this function, plus an If test, you can tell whether it’s Saturday or Sunday.

Example of script:

If Weekday(Now) = 1 Then
    MsgBox “Sunday”
ElseIf Weekday(Now) = 7 Then
    MsgBox “Saturday”
Else
    MsgBox “Neither Saturday nor Sunday”
End If

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *