Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Contact us
Hide Buttons

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
Constant Value Description
vbUseSystem 0 Use the NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

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
Constant Value Description
vbUseSystem 0 Use the NLS API setting.
vbSunday 1 Sunday (default)
vbMonday 2 Monday
vbTuesday 3 Tuesday
vbWednesday 4 Wednesday
vbThursday 5 Thursday
vbFriday 6 Friday
vbSaturday 7 Saturday

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()

You may also like...

Leave a Reply

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

%d bloggers like this: