WEEKDAY(date, [firstdayofweek])

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


dateThe date you want the day for (Date).
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 docs.microsoft.com

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

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

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

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