Results 1 to 10 of 10

Thread: *** Resolved*** How to determine next Friday's date

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381

    *** Resolved*** How to determine next Friday's date

    Does someone know how to find the date for the next Friday based on the current date?

    Rev. Michael L. Burns
    Last edited by Rev. Michael L. Burns; Jan 2nd, 2002 at 04:53 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    How about
    VB Code:
    1. Private Sub Command1_Click()          
    2.           Dim FridaysDate As Variant
    3.           Select Case Weekday(Now)
    4.             Case 1
    5.             FridaysDate = Now + 5
    6.             Case 2
    7.             FridaysDate = Now + 4
    8.             Case 3
    9.             FridaysDate = Now + 3
    10.             Case 4
    11.             FridaysDate = Now + 2
    12.             Case 5
    13.             FridaysDate = Now
    14.             Case 6
    15.             FridaysDate = Now + 7
    16.             Case 7
    17.             FridaysDate = Now + 6
    18.          End Select
    19.          FridaysDate = Format(FridaysDate, "mm/dd/yyyy")
    20.          MsgBox FridaysDate          
    21. End Sub

  3. #3
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    VB Code:
    1. Dim blnFriday as Boolean
    2. Dim dtDay as Date
    3.  
    4. dtDay = Now + 1
    5.  
    6. Do
    7.  
    8.      If Format(dtDay, "dddd") = "Friday" Then
    9.           MsgBox "Next Friday is " & dtDate
    10.           blnFriday = True
    11.      Else
    12.           dtDay = dtDay + 1
    13.           blnFriday = False
    14.      End If
    15.  
    16. Loop Until blnFriday = True
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    No need to loop or to use Select Case
    VB Code:
    1. Public Function NextFriday() As Date
    2.     Dim intDay As Integer
    3.    
    4.     'if the toaday's weekday is more then Friday, then calculate
    5.     'number of days until next Friday, otherwise, get the difference between today and Next Friday
    6.     intDay = IIf(WeekDay(Date) > vbFriday, vbSaturday - vbFriday, vbFriday - WeekDay(Date))
    7.    
    8.     NextFriday = DateAdd("d", intDay, Date)
    9. End Function

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Hack, seoptimizer2001, and Serge,

    Thanks for the assitance. With the exception of one typeo in seoptimizer2001 response (dtDate instead of dtDay), all three solutions work great.

    I also found a routine hidden deep within Total VB Sourcebook 6 that when used can determine any day of the week after a given date.


    Public Function NextDOW(datDateIn As Date, intDay As Integer) As Date
    ' Comments : Returns the specified day of the week after the given
    ' date (eg. NextDOW (#03/28/64#, 6) returns the date of
    ' the next friday after 03/28/64)
    ' Parameters: datDateIn - date to check
    ' intDay - day of week to calculate (1=Sunday, 7=Saturday)
    ' Returns : date
    ' Source : Total VB SourceBook 6
    '
    On Error GoTo PROC_ERR

    NextDOW = datDateIn - WeekDay(datDateIn) + intDay + _
    IIf(WeekDay(datDateIn) < intDay, 0, 7)

    PROC_EXIT:
    Exit Function

    PROC_ERR:
    MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
    "NextDOW"
    Resume PROC_EXIT

    End Function

    Usage Example:

    Dim datTest As Date

    datTest = "01/15/2002"

    Debug.Print "The next Friday after " & datTest & " is " & _
    NextDOW(datTest, 6)

    Rev. Michael L. Burns

  6. #6
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629

    hi Michael use the [Highlight=VB] tag :p

    VB Code:
    1. Public Function NextDOW(datDateIn As Date, intDay As Integer) As Date
    2.   ' Comments : Returns the specified day of the week after the given
    3.   ' date (eg. NextDOW (#03/28/64#, 6) returns the date of
    4.   ' the next friday after 03/28/64)
    5.   ' Parameters: datDateIn - date to check
    6.   ' intDay - day of week to calculate (1=Sunday, 7=Saturday)
    7.   ' Returns : date
    8.   ' Source : Total VB SourceBook 6
    9.   '
    10.   On Error GoTo PROC_ERR
    11.  
    12.   NextDOW = datDateIn - WeekDay(datDateIn) + intDay + _
    13.   IIf(WeekDay(datDateIn) < intDay, 0, 7)
    14.  
    15. PROC_EXIT:
    16.   Exit Function
    17.  
    18. PROC_ERR:
    19.   MsgBox "Error: " & Err.Number & ". " & Err.Description, , _
    20.   "NextDOW"
    21.   Resume PROC_EXIT
    22.  
    23. End Function

    Usage Example:

    VB Code:
    1. Dim datTest As Date
    2.  
    3. datTest = "01/15/2002"
    4.  
    5. Debug.Print "The next Friday after " & datTest & " is " & _
    6. NextDOW(datTest, 6)

    makes my life easier

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Sorry Peet. With this thick skull of mine ya lost me here. Can you please explain?

    Pastor Mike

  8. #8
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Rev, check the link in my signature, but instead of the code or php tags use vbcode tags. I know they aren't listed, but they do work. It just makes code easier to read.
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  9. #9
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    Originally posted by Rev. Michael L. Burns
    Sorry Peet. With this thick skull of mine ya lost me here. Can you please explain?

    Pastor Mike
    sorry.. should have explained it better

    when typing/pasting code, place it inbetween vbcode tags like this :

    [vbcode]
    Dim s As String
    s = "ABC"
    MsgBox s
    [/vbcode]

    it will when u post it look like this:

    VB Code:
    1. Dim s As String
    2.   s = "ABC"
    3.   MsgBox s

    makes it a lot easier to read and understand

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Location
    Edgerton, WI
    Posts
    381
    Thanks Peet. I always wondered how that was done but never took the time to investegate. Will try to use it in the future.

    Pastor Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width