WEEKDAY

WEEKDAY(date, [firstdayofweek])

Returns the number representing the day of the week for a given date (Integer).


dateThe date you want the day for (Variant).
firstdayofweek(Optional) A vbDayOfWeek constant that specifies the first day of the week (Integer):
0 = vbUseSystemDayOfWeek
1 = vbSunday (default)
2 = vbMonday
3 = vbTuesday
4 = vbWednesday
5 = vbThursday
6 = vbFriday
7 = vbSaturday

REMARKS
* If "firstdayofweek" is left blank, then 1 (vbSunday) is used.
* If "firstdayofweek" = vbUseSystemDayOfWeek, this takes the setting from the Control Panel, Region.
* If the Calendar property setting is Gregorian, the returned integer represents the Gregorian day of the week for the date argument.
* If the calendar is Hijri, the returned integer represents the Hijri day of the week for the date argument.
* For Hijri dates, the argument number is any numeric expression that can represent a date and/or time from 1/1/100 (Gregorian Aug 2, 718) through 4/3/9666 (Gregorian Dec 31, 9999).
* You can use the WEEKDAYNAME function to return the day of the week as a string.
* The equivalent Excel function is Application.WorksheetFunction.WEEKDAY
* The equivalent .NET function is Microsoft.VisualBasic.DateAndTime.Weekday
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print VBA.Format("06/07/2020","dddd")                          'Monday  
Debug.Print Weekday(#06/07/2020#, vbDayOfWeek.vbMonday) '7
Debug.Print Weekday(#07/07/2020#, vbDayOfWeek.vbMonday) '2
Debug.Print Weekday(#08/07/2020#, vbDayOfWeek.vbMonday) '5
Debug.Print Weekday(#12/07/2020#, vbDayOfWeek.vbMonday) '1
Debug.Print Weekday(#06/07/2020#, vbDayOfWeek.vbSunday) '1
Debug.Print Weekday(#06/07/2020#, vbDayOfWeek.vbSunday) '1
Debug.Print Weekday(#06/07/2020#, vbDayOfWeek.vbMonday) '7 / vbDayOfWeek.vbSaturday
Debug.Print Weekday(#06/07/2020#, vbDayOfWeek.vbTuesday) '6 / vbDayOfWeek.vbFriday
Debug.Print Weekday(#06/07/2020#, vbDayOfWeek.vbUseSystemDayOfWeek) '7 / vbDayOfWeek.vbSaturday

Debug.Print Weekday(VBA.Date) '2
Debug.Print Weekday(VBA.Date, vbDayOfWeek.vbMonday) '1
Debug.Print Weekday(VBA.Date, vbDayOfWeek.vbUseSystemDayOfWeek) '1

Debug.Print Weekday(VBA.Now, vbDayOfWeek.vbSunday) '1, run on a Sunday
Debug.Print Weekday(VBA.Now, vbDayOfWeek.vbMonday) '1, run on a Monday

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top