WeekdayName - VBScript


Overview

The WeekdayName command in VB Script retrieves the full name of a specified numeric weekday, typically from 1 to 7. It is widely used for displaying or formatting date-related information in scripts and applications.

Syntax

WeekdayName(weekday_numeric)

Parameters

  • weekday_numeric: A numeric value representing the weekday, where:
    • 1 = Sunday
    • 2 = Monday
    • 3 = Tuesday
    • 4 = Wednesday
    • 5 = Thursday
    • 6 = Friday
    • 7 = Saturday

Examples

Dim weekday_number = 3
MsgBox WeekdayName(weekday_number) ' Displays "Tuesday"
Dim myDate = "2023-07-10"
Dim weekday_number = CreateObject("WScript.Shell").RegRead("HKCU\Control Panel\International\Calendars\FirstDayOfWeek")
MsgBox WeekdayName(weekday_number) & ", " & FormatDateTime(myDate, vbLongDate) ' Displays "Monday, July 10, 2023"

Common Issues

  • Incorrect weekday number: Ensure that the weekday number provided is within the valid range (1-7).
  • Non-numeric input: The weekday_numeric parameter must be numeric. Providing non-numeric values will result in an error.

Integration

The WeekdayName command can be used in combination with other VB Script functions for advanced date formatting and manipulation. For example:

Dim myDate = "2023-07-10"
Dim weekday_name = WeekdayName(CreateObject("WScript.Shell").RegRead("HKCU\Control Panel\International\Calendars\FirstDayOfWeek"))
MsgBox "Next " & weekday_name & " is " & FormatDateTime(DateAdd("d", 7 - weekday_number, myDate), vbLongDate)
  • Date
  • FormatDateTime
  • DateAdd