leap year calculation

Reply

Join Date: Nov 2005
Posts: 4
Reputation: addys is an unknown quantity at this point 
Solved Threads: 0
addys addys is offline Offline
Newbie Poster

leap year calculation

 
0
  #1
Nov 21st, 2005
'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
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 483
Reputation: campkev is an unknown quantity at this point 
Solved Threads: 19
campkev campkev is offline Offline
Posting Pro in Training

Re: leap year calculation

 
0
  #2
Nov 23rd, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 4
Reputation: addys is an unknown quantity at this point 
Solved Threads: 0
addys addys is offline Offline
Newbie Poster

Re: leap year calculation

 
0
  #3
Nov 28th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 166
Reputation: Lafinboy is an unknown quantity at this point 
Solved Threads: 7
Lafinboy's Avatar
Lafinboy Lafinboy is offline Offline
Junior Poster

Re: leap year calculation

 
0
  #4
Nov 28th, 2005
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:
  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. %>
If I've been a help please confirm by clicking the Add to Lafinboy's Reputation link in the header of this reply.

Lafinboy Productions
:: Website Design :: Website Development ::

Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC