Solved

Date filter..asp

Posted on 2004-08-05
10
364 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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 …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

12 Experts available now in Live!

Get 1:1 Help Now