Results 1 to 10 of 10

Thread: calculating Next Thursday....

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    calculating Next Thursday....

    Hello , Good Morning all,

    I am trying to write a function that calculates next thursday (for next 6 months) function

    if some one has some ideas can you please share?

    thanks
    nath

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: calculating Next Thursday....

    I don't really understand what you mean by 'for next 6 months'. here's a fucntion for getting the next day:

    VB Code:
    1. Private Sub Form_Load()
    2.     Debug.Print NextDate(vbThursday, Now)
    3. End Sub
    4.  
    5. Private Function NextDate(ByVal iDay As VbDayOfWeek, ByVal dAfter As Date) As Date
    6.     Do
    7.         dAfter = DateAdd("d", 1, dAfter)
    8.     Loop Until Weekday(dAfter) = iDay
    9.     NextDate = dAfter
    10. End Function

  3. #3
    Fanatic Member THEROB's Avatar
    Join Date
    Oct 2000
    Location
    I'm cold and there are wolves after me
    Posts
    575

    Re: calculating Next Thursday....

    For the next 6 months (26 weeks):
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim dToday As Date
    3.     Dim iLoop As Long
    4.    
    5.     dToday = NextDate(vbThursday, Now)
    6.    
    7.     For iLoop = 1 To 26
    8.         Debug.Print dToday
    9.         dToday = dToday + 7
    10.     Next
    11. End Sub
    12. Private Function NextDate(ByVal iDay As VbDayOfWeek, ByVal dAfter As Date) As Date
    13.     Do
    14.         dAfter = DateAdd("d", 1, dAfter)
    15.     Loop Until Weekday(dAfter) = iDay
    16.     NextDate = dAfter
    17. End Function
    My secretary hopes that I will pay her, her landlord hopes that she will produce some rent, the Electricity Board hopes that he will settle their bill, and so on. I find it a wonderfully optimistic way of life. [Dirk Gently]

  4. #4
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: calculating Next Thursday....

    Hi All

    This thread interested me. I would like to add such text "Next Saturday will be:"

    How I can make this?

    Thx in advance
    I know, I know, my English is bad, sorry .....

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: calculating Next Thursday....

    Try the function i posted, you can set the day that it looks for to any of the days of the weeks, ie:

    VB Code:
    1. Debug.Print NextDay(vbSaturday, Now)

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: calculating Next Thursday....

    Quote Originally Posted by bushmobile
    Try the function i posted, you can set the day that it looks for to any of the days of the weeks.
    In fact, you could put a listbox on the form with all of the names of the week days in it, and just have the user make a selection, and pass the selection to bush's function.

  7. #7
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: calculating Next Thursday....

    ok, I made like this:
    VB Code:
    1. Private Sub Command1_Click()
    2.  Label1.Caption = "Next Saturday will be:" & " " & NextDate(vbSaturday, Now) '<<< I separated text a bit
    3. End Sub
    4.  
    5.  
    6. Private Function NextDate(ByVal iDay As VbDayOfWeek, ByVal dAfter As Date) As Date
    7.     Do
    8.         dAfter = DateAdd("d", 1, dAfter)
    9.     Loop Until Weekday(dAfter) = iDay
    10.     NextDate = dAfter
    11. End Function

    I have small question,
    how to throw out time ( I want to leave only date)?

    thx
    I know, I know, my English is bad, sorry .....

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: calculating Next Thursday....

    VB Code:
    1. 'replace Now with
    2. Format(Now, "mm/dd/yyyy")

  9. #9
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: calculating Next Thursday....

    or:
    VB Code:
    1. Format$(NextDate(vbSaturday, Now), "dd/mm/yyyy")

  10. #10
    Hyperactive Member
    Join Date
    Jun 2005
    Location
    in Poland
    Posts
    390

    Re: calculating Next Thursday....

    I made so first:

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim NewDate As Date
    3. NewDate = Format(Now, "mm/dd/yyyy")
    4. Label1.Caption = "Next Saturday will be:" & " " & NextDate(vbSaturday, NewDate)
    5. End Sub

    but realy I see, that Bush gave a pretty piece of code, and it will be better so

    great thanks for both
    I greet
    Last edited by Tamgovb; Apr 28th, 2006 at 02:37 AM.
    I know, I know, my English is bad, sorry .....

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