Link to home
Start Free TrialLog in
Avatar of MaximusMeridus
MaximusMeridus

asked on

Date filter..asp

Hi all,

How do I display the date of the last friday of this month


ie I want to show the date of the last friday for this month
in the following format.

27 August

If we roll on into September then the last friday will be

24 September

Many thanks
Avatar of Gary
Gary
Flag of Ireland image

<%
response.write getFriday("12/11/04")

function getFriday(strdate)
   for count=1 to 7
      tmpdate=month(strdate)+1 & "/" & 1 & "/" & year(strdate)
      tmpdate=dateadd("d",-count,tmpdate)
      if instr(formatdatetime(tmpdate,1),"Fri")>0 then exit for
   next
   getFriday formatdatetime(tmpdate,1)
end function
%>
Avatar of MaximusMeridus
MaximusMeridus

ASKER

Hi Gary,

I am getting the following error

Error Type:
Microsoft VBScript runtime (0x800A001C)
Out of stack space: 'getFriday'

<%
response.write getFriday("12/12/04")

function getFriday(strdate)
   olddate=dateadd("m",1,strdate)
   tmpdate= year(olddate) & "/" & month(olddate) & "/" & "1"
   for count=1 to 7
      tmpdate=dateadd("d",-count,tmpdate)
      if instr(formatdatetime(tmpdate,1),"Fri")>0 then exit for
   next
   getFriday=formatdatetime(tmpdate,1)
end function
%>
This gives me

04 December 2004


I need the last friday of the current month. which ever the current may be

ie current month is August

therefore

last friday falls on

27 August
ASKER CERTIFIED SOLUTION
Avatar of neeraj523
neeraj523
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
It may be getting confused over the date format, try passing the date in format yyyy/mm/dd
MaximusMeridus  - what is your date format? (mm/dd/yyyy, dd/mm/yyyy, yyyy/mm/dd)?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here you go:

<%
BaseDate = date
EndOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, 0)
for x=0 to 6
EndOfMonth=EndOfMonth-1
if WeekDayName(WeekDay(EndOfMonth)) = "Friday" then
      response.write EndOfMonth
end if
next
%>

Barry62
Any luck with my function?