| | |
leap year calculation
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2005
Posts: 4
Reputation:
Solved Threads: 0
'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
'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
•
•
Join Date: Jul 2005
Posts: 483
Reputation:
Solved Threads: 19
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
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
•
•
Join Date: Nov 2005
Posts: 4
Reputation:
Solved Threads: 0
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
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
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:
A quick example:
ASP Syntax (Toggle Plain Text)
<% dim strMonth, strDay, strYear, strDate strMonth = "2" strDay = "23" strYear = "2004" strDate = strMonth & "/" & strDay & "/" & strYear response.write dateAdd("d", 7, strDate) ' will add 7 days to the supplied date and change days, months, years as required %>
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 ::
Lafinboy Productions
:: Website Design :: Website Development ::
![]() |
Similar Threads
- leap year (C)
Other Threads in the ASP Forum
- Previous Thread: Final Year Project
- Next Thread: problem running asp scripts in windows xp pro
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection diagnostics dreamweaver excel fso iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit webserver windows7





