|
-
Jan 2nd, 2002, 03:30 PM
#1
Thread Starter
Hyperactive Member
*** 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.
-
Jan 2nd, 2002, 03:47 PM
#2
How about
VB Code:
Private Sub Command1_Click()
Dim FridaysDate As Variant
Select Case Weekday(Now)
Case 1
FridaysDate = Now + 5
Case 2
FridaysDate = Now + 4
Case 3
FridaysDate = Now + 3
Case 4
FridaysDate = Now + 2
Case 5
FridaysDate = Now
Case 6
FridaysDate = Now + 7
Case 7
FridaysDate = Now + 6
End Select
FridaysDate = Format(FridaysDate, "mm/dd/yyyy")
MsgBox FridaysDate
End Sub
-
Jan 2nd, 2002, 03:48 PM
#3
Frenzied Member
VB Code:
Dim blnFriday as Boolean
Dim dtDay as Date
dtDay = Now + 1
Do
If Format(dtDay, "dddd") = "Friday" Then
MsgBox "Next Friday is " & dtDate
blnFriday = True
Else
dtDay = dtDay + 1
blnFriday = False
End If
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!

-
Jan 2nd, 2002, 04:00 PM
#4
No need to loop or to use Select Case
VB Code:
Public Function NextFriday() As Date
Dim intDay As Integer
'if the toaday's weekday is more then Friday, then calculate
'number of days until next Friday, otherwise, get the difference between today and Next Friday
intDay = IIf(WeekDay(Date) > vbFriday, vbSaturday - vbFriday, vbFriday - WeekDay(Date))
NextFriday = DateAdd("d", intDay, Date)
End Function
-
Jan 2nd, 2002, 04:52 PM
#5
Thread Starter
Hyperactive Member
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
-
Jan 2nd, 2002, 04:58 PM
#6
-= B u g S l a y e r =-
hi Michael use the [Highlight=VB] tag :p
VB Code:
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:
VB Code:
Dim datTest As Date
datTest = "01/15/2002"
Debug.Print "The next Friday after " & datTest & " is " & _
NextDOW(datTest, 6)
makes my life easier
-
Jan 2nd, 2002, 05:10 PM
#7
Thread Starter
Hyperactive Member
Sorry Peet. With this thick skull of mine ya lost me here. Can you please explain?
Pastor Mike
-
Jan 2nd, 2002, 05:19 PM
#8
Frenzied Member
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!

-
Jan 2nd, 2002, 05:52 PM
#9
-= B u g S l a y e r =-
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:
Dim s As String
s = "ABC"
MsgBox s
makes it a lot easier to read and understand
-
Jan 3rd, 2002, 07:16 AM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|