
- VBA Tutorial
- VBA - Home
- VBA - Overview
- VBA - Excel Macros
- VBA - Excel Terms
- VBA - Macro Comments
- VBA - Message Box
- VBA - Input Box
- VBA - Variables
- VBA - Constants
- VBA - Operators
- VBA - Decisions
- VBA - Loops
- VBA - Strings
- VBA - Date and Time
- VBA - Arrays
- VBA - Functions
- VBA - Sub Procedure
- VBA - Events
- VBA - Error Handling
- VBA - Excel Objects
- VBA - Text Files
- VBA - Programming Charts
- VBA - Userforms
- VBA Useful Resources
- VBA - Quick Guide
- VBA - Useful Resources
- VBA - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
VBA - WeekDay
The WeekDay function returns an integer from 1 to 7 that represents the day of the week for the specified date.
Syntax
Weekday(date[,firstdayofweek])
Parameter Description
Date − A required parameter. The weekday will return a specified date.
Firstdayofweek − An optional parameter. Specifies the first day of the week. It can take the following values.
0 = vbUseSystemDayOfWeek - Use National Language Support (NLS) API setting
1 = vbSunday - Sunday
2 = vbMonday - Monday
3 = vbTuesday - Tuesday
4 = vbWednesday - Wednesday
5 = vbThursday - Thursday
6 = vbFriday - Friday
7 = vbSaturday - Saturday
Example
Add a button and add the following function.
Private Sub Constant_demo_Click() msgbox("Line 1: " & Weekday("2013-05-16",1)) msgbox("Line 2: " & Weekday("2013-05-16",2)) msgbox("Line 3: " & Weekday("2013-05-16",2)) msgbox("Line 4: " & Weekday("2010-02-16")) msgbox("Line 5: " & Weekday("2010-02-17")) msgbox("Line 6: " & Weekday("2010-02-18")) End Sub
When you execute the above function, it produces the following output.
Line 1: 5 Line 2: 4 Line 3: 4 Line 4: 3 Line 5: 4 Line 6: 5
vba_date_time.htm
Advertisements