Given a date as input, how can I determine whether the day falls on a weekend?
相关问题
- Excel sunburst chart: Some labels missing
- Error handling only works once
- Error handling only works once
- Excel formula in VBA code
- Excel VBA run time error 450 from referencing a ra
相关文章
- Get column data by Column name and sheet name
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- Unregister a XLL in Excel (VBA)
- How to prevent excel from truncating numbers in a
- numeric up down control in vba
- Declare a Range relative to the Active Cell with V
- What's the easiest way to create an Excel tabl
This is the most direct way to determine if
MyDate
falls on the weekend:The Weekday() function has an optional 2nd parameter that tells it which day of the week the week starts on. The Weekday() function returns an integer from 1 through 7.
I've instructed it to start the week on MONDAY and so SATURDAY would be 6 and SUNDAY would be 7.
Or, you can use this:
or
as a formula.
since 1 is Sunday and 0 is Saturday
There is a Weekday function that takes a Date as an argument and returns the day (1, 2, 3, etc.)
The return values are:
Assuming that weekends are Saturday and Sunday, the function would look like this:
Formula for converting date to week days
Selection.FormulaR1C1 = "=TEXT(WEEKDAY(R7C" + CStr(i) + ",1),""ddd"")"
this will return day
eg:- if input is 02-may-2013 then it will return Thu --> (thursday) here variable i represents another column