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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What date is last week Friday? 2

Status
Not open for further replies.

siebel2002

Programmer
Oct 8, 2001
102
0
0
US
I would appreciate any help in snippet of code to determine the date for last Friday. Thank you..
 
You can use the WeekDay function to return the day of the week that today is

So
Code:
Today       Weekday 
Monday         1
Tuesday        2
Wednesday      3
Thursday       4
Friday         5
Saturday       6
Sunday         7

Date() - 7 take you to today's day LAST week
Then add back 5 ( for Friday ) Minus the WeekDay

So Friday last week = Date() - 7 + ( 5 - WeekDay )

Which simplifies to = Date() - 2 - WeekDay

You might need to adjust the -2 if your difinition of week ending date disagrees with mine.


'ope-that-'elps.





G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
lastfri: [dDt] - IIf(Format([dDt], "w") = 7, 1, Format([dDt], "w") + 1)
 
And an approach similiar to mpastore's using a function
which allows the user to specify the specific day of
week prior to the specified date:
Code:
Function LastNDay(pDay As Date, wday As Integer) As Date
'*******************************************
'Name:      LastNDay (Function)
'Purpose:   Find date of  day of week (Sun, Mon, etc)
'           preceding a specified date
'Inputs:    (1) ? LastNDay(date(), 3)      'Tuesday
'           (2) ? LastNDay(#28-May-03#, 6) 'Saturday
'Output:    (1) 5/27/03 'Today's date = 5/29/03
'           (2) 5/23/03
'*******************************************

LastNDay = [pDay] - (WeekDay([pDay]) + IIf(WeekDay([pDay]) <= wday, 7, 0) - wday)

End Function
 
Good morning Raskew:

What an elegant solution indeed!

Thank you

 
Public Function Initalize_Report_TimePeriod(DateIn As Date) As Variant

ReportEndDate = DateIn - WeekDay(DateIn, vbSaturday) ' Friday of Last Week

End Function


HA ???

TIA
 
Hey, TLady, you rock :)

Mike Pastore

Hats off to (Roy) Harper
 
I have more of these, ask if you need some.
Thanks,
I feel like a STAR !

TIA
 
So is the idea that you have seven functions, one for each day of the week? Hmmm!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top