Solved

Date filter..asp

Posted on 2004-08-05
10
381 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

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