Be the first user to complete this post
|
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
- Mandatory
- 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
_________________________________________________________________________________
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
- Mandatory
- 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
Also Read:
- VBA-Excel: Cells Ranges Offset - Active Cell
- VBA-Excel: Arrays – One Dimension, Static Array
- VBA-Excel: Date-Time Functions – TimeSerial() and TimeValue()
- VBA Excel – Looping Through a Range of Cells
- VBA-Excel: Date-Time Functions – DateSerial()