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

dateserial to find monday's date of previous week 1

Status
Not open for further replies.

lorca

Technical User
Dec 20, 2005
64
GB
Hi

I used the following code to find the first date from the previous month e.g. 01/05/2006
I'd like to return the date for the monday of the previous week so e.g. 19/06/2006 and also friday's date of the previous wek e.g. 23/06/2006

any ideas ?

thanks
rich

Code:
=left(format(DateSerial(iif( Month(DateTime.Now)=1, Year(DateTime.Now)-1, Year(DateTime.Now)), iif( Month(DateTime.Now)=1, 12, Month(DateTime.Now) - 1), 1),"dd/MM/yyyy"),10)
 
You can use the DateAdd function to get a date by adding or subtracting time intervals from a given date.

Dim d As Date
Dim d2 As Date
Dim d3 As Date

d = CType("6/26/2006", Date)

'subtract 7 days
d2 = DateAdd(DateInterval.Day, -7, d)

MsgBox(d2.ToString)

'subtract 3 days
d3 = DateAdd(DateInterval.Day, -3, d)

MsgBox(d3.ToString)



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
thanks

because i wanted it automated, but i know the report is always run on a monday i used this for the previous monday and just minused 3 for the previous friday.

Code:
=left(format(DateAdd(DateInterval.Day, -7,datetime.now),"dd/MM/yyyy"),10)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top