Weekday - VBScript


Weekday

Overview

The Weekday command in VB Script returns the day of the week for a given date. It is commonly used to determine the weekday corresponding to a specific date, facilitating operations like scheduling, date manipulation, and date calculations.

Syntax

Weekday([date])

Parameters:

  • date: (Optional) A Date value representing the date for which to determine the weekday. If omitted, the current system date is used.

Options/Flags

None.

Examples

  • Get the weekday for today’s date:
Weekday()
  • Check if a date falls on a weekend:
If Weekday("2023-03-18") >= 6 Then
    ' Date falls on a weekend
End If
  • Find the weekday for a specific date:
Weekday("1989-07-04")

Common Issues

  • Invalid date format: Ensure the date parameter is a valid Date value.
  • Range error: Weekday values can range from 1 (Sunday) to 7 (Saturday). Invalid or out-of-range dates will result in an error.

Integration

Weekday can be used in conjunction with other date-related commands in VB Script, such as DateAdd and DateDiff. For example:

' Add 7 days to the current date and get the new weekday
Weekday(DateAdd("d", 7, Now))

Related Commands

  • Date
  • DateAdd
  • DateDiff