Solved

Date filter..asp

Posted on 2004-08-05
10
388 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

828 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