Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Workdays 1

Status
Not open for further replies.

Chance1234

IS-IT--Management
Jul 25, 2001
7,871
US
I need help on a function that returns the date 2 working days before the current date, so if the date was monday it would return thursdays date the week before

im this far

Function fUnCntTwoDatysBack(Togo As Date)
Dim IsWeekend As Boolean

Togo = Togo - 2

Select Case Weekday(Togo)
Case vbSaturday, vbSunday
IsWeekend = True
Case Else
IsWeekend = False
End Select

Chance

 
try something on the lines of this:

Dim d As Date
d = DateAdd("d", -2, Date)

Select Case Weekday(d)

Case vbSunday
MsgBox "sunday"
Case vbSaturday
MsgBox "saturday"
Case Else
MsgBox "weekday"
End Select Nick (Everton Rool OK!)
 
Sorry, I hadn't quite finished it:

Sub getDate()
Dim d As Date
d = DateAdd("d", -2, Date)

Select Case Weekday(d)

Case vbSunday
d = DateAdd("d", -2, d)
Case vbSaturday
d = DateAdd("d", -1, d)
End Select

End Sub Nick (Everton Rool OK!)
 
I realise that it is already done in a function, but thought I'd add the formula solution:
=IF(WEEKDAY(TODAY())=1,TODAY()-3,IF(OR(WEEKDAY(TODAY())=2,WEEKDAY(TODAY())=3),TODAY()-4,TODAY()-2))

Geoff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top