WeekdayName Function (VB6)

Syntax

WeekdayName(WeekdayNo, [abbreviate [, FirstDayOfWeek]])

WeekdayNo

Use: Required

Data Type: Long

The ordinal number of the required weekday from 1 to 7.

abbreviate

Use: Optional

Data Type: Boolean

Specifies whether to return the full day name or an abbreviation.

FirstDayOfWeek

Use: Optional

Data Type: vbDayOfWeek constant

Specifies which day of the week should be first.

Return Value

A String

Description

Returns the real name of the day.

Rules at a Glance

  • WeekDayNo must be a number between 1 and 7, or the function generates runtime error 5, "Invalid procedure call or argument."

  • If FirstDayOfWeek is omitted, WeekdayName treats Sunday as the first day of the week.

  • The default value of abbreviate is False.

Programming Tips and Gotchas

  • WeekdayName with abbreviate set to False is the equivalent of Format (dateval, "dddd").

  • WeekdayName with abbreviate set to True is the equivalent of Format (dateval, "ddd").

  • You'd expect that, given a date, WeekDayName would return the name of that date's day. But this isn't how the function works. To determine the name of the day of a particular date, combine WeekDayName with a call to the WeekDay function, as the following code fragment shows:

    sDay = WeekDayName(Weekday(dDate, iFirstDay), _
                       bFullName, iFirstDay)

    Note that the value of the FirstDayOfWeek argument must be the same in the calls to both functions for WeekDayName to return an accurate result.

See Also

Format Function, WeekDay Function

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.