944,138 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 9193
  • ASP RSS
Nov 21st, 2005
0

leap year calculation

Expand Post »
'FromYear is the year entered by the user, extracted from the full date.
'if its not a leap year and the month is february and the user chooses the 29th of Feb the day must be overwritten with the 28th.
'if it is a leap year then it must start after the 23rd but end at 29
'Code*****

if (FromYear Mod 4 <> 0) and (FromYear Mod 100 <> 0) and (FromYear Mod 400 <>) then
if FromMonth = 2 then
if FromDay = 29 then
FromDay = 28
else FromDay = 29
end if
if FromDay > 22 then
ToDay = (FromDay + 6) - 28
ToMonth = FromMonth + 1
end if
end if
elseif FromDay > 23 and <29 then
ToDay = (FromDay + 6) - FromDay ToMonth = FromMonth + 1
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
addys is offline Offline
4 posts
since Nov 2005
Nov 23rd, 2005
0

Re: leap year calculation

I'm trying to help you out here but don't completely understand what you are trying to do. Could you post the entire question.
I get the first part where you are checking to see if it is a leap year and changing the 29th to the 28th if it is not a leap year. But I don't understand what exactly the last requirement is
Reputation Points: 14
Solved Threads: 19
Posting Pro in Training
campkev is offline Offline
484 posts
since Jul 2005
Nov 28th, 2005
0

Re: leap year calculation

hi there
thanks so much for replying.
i found a solution, but its not working a 100%
lets say the user enters 25Feb, the week must start from 25 feb and the next 7 days.
trick is that there are only 28 days in a non-leap year so it must jump from feb to 4 March. i'll show u the leap yr calc ok.

(the part that is commented out doesnt work)

if StrComp(TypeOfReport,"Weekly",0) = 0 then
FromMonth = CInt(request("datemonth"))
FromYear = CInt(request("dateyear"))
FromDay = CInt(request("dateday"))

ToYear = FromYear
ToMonth = FromMonth
ToDay = FromDay + 6

if FromDay = 0 then
FromDay = 1
end if

if FromMonth = 0 then
FromMonth = 1
FromDay = 1
ToDay = FromDay + 6
ToMonth = 1
ToYear = FromYear +1
end if

if ToMonth = 13 then
ToDay = FromDay + 6
ToMonth = 1
ToYear = FromYear + 1
end if

'if (FromYear Mod 4 <> 0) 'and (FromYear Mod 100 <> 0) and (FromYear Mod 400 <>) then
if FromMonth = 2 then
'if FromDay = 29 then
' FromDay = 28
' else FromDay = 29
'end if
if FromDay > 22 then
ToDay = (FromDay + 6) - 28
ToMonth = FromMonth + 1
end if
end if
'elseif FromDay > 23 then
' ToDay = (FromDay + 6) - FromDay
' ToMonth = FromMonth + 1

Thx
Addy
Reputation Points: 10
Solved Threads: 0
Newbie Poster
addys is offline Offline
4 posts
since Nov 2005
Nov 28th, 2005
0

Re: leap year calculation

You seem to be making a lot of hard work for yourself when there are built in functions that will do all of the date calculation work for you. Look into using the DATEADD function, maybe coupled with DATEPART and then you just need to pass in valid dates, plus or minus any number of units of time measurement to get the required results.

A quick example:
ASP Syntax (Toggle Plain Text)
  1. <%
  2. dim strMonth, strDay, strYear, strDate
  3. strMonth = "2"
  4. strDay = "23"
  5. strYear = "2004"
  6. strDate = strMonth & "/" & strDay & "/" & strYear
  7. response.write dateAdd("d", 7, strDate) ' will add 7 days to the supplied date and change days, months, years as required
  8. %>
Reputation Points: 16
Solved Threads: 7
Junior Poster
Lafinboy is offline Offline
166 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: Final Year Project
Next Thread in ASP Forum Timeline: problem running asp scripts in windows xp pro





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC