Custom Search

Monday, July 2, 2012

Write a code to get last Friday date.

'Gets the last friday's date


strCurrentSysDate = Date
strModDate = dateadd("ww",-1,strCurrentSysDate)
numWeekDay = 6- weekday(strModDate)
strModifiedDate = dateadd("d",numWeekDay,strModDate)
strmonth =left(monthname(month(strModifiedDate)),3)
If len(cstr(day(strModifiedDate))) < 2 Then
strDate = "0"&day(strModifiedDate)
else
strDate = day(strModifiedDate)
End If
strYear = year(strModifiedDate)
strPrevDate = strmonth& "/" & strDate & "/" & strYear
Msgbox strPrevDate