?
Solved

Date filter..asp

Posted on 2004-08-05
10
Medium Priority
?
398 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:MaximusMeridus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 11724987
<%
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
%>
0
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 11725054
Hi Gary,

I am getting the following error

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

Expert Comment

by:Gary
ID: 11725155

<%
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
%>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:MaximusMeridus
ID: 11725299
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
0
 
LVL 22

Accepted Solution

by:
neeraj523 earned 1600 total points
ID: 11725325
Hello

You can also try this

======================================================
<%
lastDate = "05-Aug-04"
lastDate = DateAdd("m",1,lastDate)
lastDate = DateAdd("d",-Day(lastDate),lastDate)

if WeekDay(lastDate) = 6 Then
      lastFriday = lastDate
Elseif WeekDay(lastDate) < 6 Then
      lastFriday = dateAdd("d",-(WeekDay(lastDate)+1),lastDate)
Else
      lastFriday = dateAdd("d",-1,lastDate)
End if
Response.Write Right("00" & Day(lastFriday),2) & " " & MonthName(Month(lastFriday))
======================================================

neeraj523
0
 
LVL 58

Expert Comment

by:Gary
ID: 11725351
It may be getting confused over the date format, try passing the date in format yyyy/mm/dd
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11725822
MaximusMeridus  - what is your date format? (mm/dd/yyyy, dd/mm/yyyy, yyyy/mm/dd)?
0
 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 400 total points
ID: 11726015
This should do it:

<%
function LastFriday()
m = month(now()) & "/1/" & year(now)
n = dateadd("m", 1, m)

do until d = 6 or a = 100
   d = weekday(n)
   n = dateadd("d", -1, n)
   a = a + 1  '<-----escape
   
loop
if a >= 100 then
  LastFriday = "Some error"
else
    n = dateadd("d", 1, n)
    LastFriday =  "Last Friday is: " & formatdatetime(n,1)
end if
end function

Response.Write LastFriday
%>
0
 
LVL 8

Expert Comment

by:Barry62
ID: 11726067
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
0
 
LVL 31

Expert Comment

by:alorentz
ID: 11729850
Any luck with my function?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question