How can you find the date of the next Friday? (If today is Friday, the date should be today's.)
Ted's solution is:
' Get the date of the next Friday.
' Get today's day number, starting with Saturday = 1,
' using the Format$ statement. Subtract the result from
' 7 to get the number of days until Friday. Use DateAdd
' to add that number of days to today's date.
MsgBox DateAdd("d", 7 - Format$(Date, "w", vbSaturday), Date)
(With relatively confusing code such as this, the comment describing the solution can be much longer than the solution itself.)
Willy Vanhaelen proposes this solution:
' Get the date of the next Friday.
' Get today's day number where Saturday = 1.
' Subtract from 7. That gives the number of
' days between now and the next Friday.
' Use DateAdd to add that number of days
' to today's date.
MsgBox DateAdd("d", 7 - WeekDay(Date, vbSaturday), Date)
|