Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating lastweekend date

Status
Not open for further replies.

msdotnet

Programmer
Jun 13, 2002
4
US
Hi folks,

Iam having trouble in finding last weekend date using asp or asp.net
Iam using calender control to calculate the lastweekend date.I can use any process not only with calendar control..
please help in this issue..

thanks in advance
 
This will work
<%
dim dtTmp, i
dtTmp = CDATE(&quot;5/31/2002&quot;) 'Last day of the month

for i = 0 to -7 step -1
if WeekDay(dateadd(&quot;d&quot;,i,dtTmp)) = 7 or
Weekday(dateadd(&quot;d&quot;,i,dtTmp)) = 1 then
dtTmp = dateadd(&quot;d&quot;,i,dtTmp)
Exit for
end if
next

Response.Write &quot;Last Weekend day of the month is :&quot; & FormatDateTime(dtTmp)
%>
 
Thanks for your guidence...I appreciate that
it works fine.. but the problem is when if I try to look for the last weekend in every month first date, its showing the same month, instead of previous month lastweekend date..
for example..if I want to see previous weekend date on 1st of june, it displays 6\1\2002 instead of 5/26/2002..

I think you understand it....Please can you suggest me in this scenario..

thanks...
 
my bad. I read last weekend of the month.

Just check the date first to see if it is the weekend.
and then back them out.
Select Case WeekDay(dtTmp)
Case 7 ' Saturday
dtTmp = DateAdd(&quot;d&quot;, -1,dtTmp)
case 1 'Sunday
dtTmp = DateAdd(&quot;d&quot;, -2,dtTmp)
end select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top