tags:

views:

176

answers:

4

no matter what day I call the function on.

I know I could write a select case weekday(now) statement, was just wondering if there was a neater way to go?

A: 
DatePart('dddd', now)

or

DatePart('dddd', #1/1/2010#) 

...with an explicit date.

George
A: 

Just subtract 7 days from the current date then get friday from that.

edit:

SET @CurDate = DATEADD(dd,-7,@CurDate);
if( DATEPART(dw,@CurDate)=6 )
BEGIN
END
C Bauer
-1 The question relates to VBA
Lunatik
Didn't realize. My mistake.
C Bauer
+2  A: 

DateAdd("d", -1 - Weekday(Now), Now)

Nick
+2  A: 

Does this help get you started? I just gave it a quick test and seemed to work ok.

Private Sub LastFriday()

Dim iWeekday As Integer

Dim LastFridayDate As Date

iWeekday = Weekday(Now(), vbFriday)

LastFridayDate = Format(Now - (iWeekday - 1), "dd-mmm-yy")

End Sub
Remnant
+1 How about just Format(Date-(weekday(date,vbFriday)-1), "dd-mmm-yy")
THEn
@THEn - Good spot - that will work and makes the code more succinct. I guess it's just a matter of style.
Remnant