Solved

Date filter..asp

Posted on 2004-08-05
10
373 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
  • 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
 
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 400 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now