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 DATE function to return the current system date.
* You can use the NOW function to return the current system date and time.
* 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/2024", "dddd")                         'Saturday  
Debug.Print Weekday(#6/7/2024#, VbDayOfWeek.vbMonday) '5
Debug.Print Weekday(#7/7/2024#, VbDayOfWeek.vbMonday) '7
Debug.Print Weekday(#8/7/2024#, VbDayOfWeek.vbMonday) '3
Debug.Print Weekday(#6/7/2024#, VbDayOfWeek.vbSunday) '6
Debug.Print Weekday(#6/7/2024#, VbDayOfWeek.vbMonday) '5 / vbDayOfWeek.vbThursday
Debug.Print Weekday(#6/7/2024#, VbDayOfWeek.vbTuesday) '4 / vbDayOfWeek.vbWednesday
Debug.Print Weekday(#6/7/2024#, VbDayOfWeek.vbUseSystemDayOfWeek) '5 / vbDayOfWeek.vbThursday

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) '2, run on a Monday
Debug.Print Weekday(VBA.Now, VbDayOfWeek.vbMonday) '1, run on a Monday

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