Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
TitleEnd of Week
Keywordsquick question answer, quiz answer, answer
Categories
 
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)

Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated