Be the first user to complete this post

  • 0
Add to List

VBA-Excel: Date-Time Functions – WeekDay() and WeekDayName()

WeekDay()

Description:

The WeekDay function takes Date as a parameter and returns a number between 1 and 7, that is the week day of the date provided.

Format:

WeekDay (strDate [Firstdayofweek])

Arguments:
  • strDate
    • Manda­tory
    • Type: Date
    • Date, whose Week Date need to be calculated.

  • Firstdayofweek
    • Optional
    • Type: Numeric
    • Specifies the first day of the week
ConstantValueDescription
vbUseSystem0Use the NLS API setting.
vbSunday1Sunday (default)
vbMonday2Monday
vbTuesday3Tuesday
vbWednesday4Wednesday
vbThursday5Thursday
vbFriday6Friday
vbSaturday7Saturday

Example:

Function FnWeekDay()

   Dim strDate

   strDate = "15-July-2013"    

   MsgBox "WeekDay of the " & strDate & " is -> " & Weekday(strDate)    

End Function
WeekDay()
WeekDay()

_________________________________________________________________________________

WeekDayName()

Description:

The WeekDayName function The takes numeric  value as a parameter and returns a week day Name.

Format:

WeekdayName(intWeekday, blnAbbreviate, firstdayofweek)

Arguments:
  • intWeekDay
    • Manda­tory
    • Type: Numeric
    • Value from 1 to 7, Monday to Sunday, whose Week Day Name need to be calculated. Like WeekDayName(1) will return “Monday”
  • blnAbbreviate
    • Optional
    • Type: Boolean
    • True value will provide the month name abbreviated, for example “Monday” will be abbreviated to “Mon”, and default value is False.
  • Firstdayofweek
    • Optional
    • Type: Numeric
    • Specifies the first day of the week
ConstantValueDescription
vbUseSystem0Use the NLS API setting.
vbSunday1Sunday (default)
vbMonday2Monday
vbTuesday3Tuesday
vbWednesday4Wednesday
vbThursday5Thursday
vbFriday6Friday
vbSaturday7Saturday

Example:

Function FnWeekDayName()

   Dim strDate

   Dim strResult

    strDate = "1-July-2013"

   strResult = "Full WeekDay Name of the " & strDate & " is -> " & WeekdayName(Weekday(strDate)) & vbCrLf

   strResult = strResult & "Abbriviated Week Day Name of the " & strDate & " is -> " & WeekdayName(Weekday(strDate), True)

   MsgBox strResult

End Function
WeekDayName()
WeekDayName()



Also Read:

  1. VBA-Excel: Create Array using Array() Function
  2. VBA-Excel: Date-Time Functions – DateValue()
  3. VBA-Excel: Date-Time Functions – Hour(), Minute(), Second()
  4. VBA-Excel: Date-Time Functions – Day()
  5. VBA-Excel: Arrays – Two Dimension, Dynamic Array