Click here to Skip to main content
15,897,226 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi
my days till has the problem..since i enter 1 year 3months and 1 day...it should be 456..instead of 1day it gives me 3 days like it increment by 2,equal to 458days. it is the same for Months and days.Years and Days it gives correct output but to include all(year,months, days,) it gives the wrong result as well..i prefer the result for days not work perfectly

VB
Public Function RaceDate(length  As Integer ) As String

              dim year As string=0
              dim month As string=0
              dim day As string=0
              dim ReturnString As string

ReturnString=""

If length = 0 then
Return String.Empty
end if

if length >= 365
year=cstr((Math.Floor (length / 365)))
length  =(length  Mod 365)

end if

If length >= 30 AndAlso length < 365 Then
month =cstr((Math.Floor(length / 30 )))
length  =(length  Mod 30)


end if

if length < 30 Then
day =cstr(length)
End If

If cint(year) >0
ReturnString= year+"  Years  "

End if

If cint(month) >0

ReturnString= ReturnString +month+" Months "

End if

If cint(day) >0

ReturnString = ReturnString+day+ " Days "

End if

Return (ReturnString)

End Function


thanks in advance
Posted

Why doing all that mess? Please see:
http://msdn.microsoft.com/en-us/library/system.datetime.aspx[^],
http://msdn.microsoft.com/en-us/library/system.datetime.adddays.aspx[^],
http://msdn.microsoft.com/en-us/library/system.datetime.addmonths.aspx[^].

Do you take into account that different years and months have different number of days, etc? Whatever. If you just want to teach yourself to program, use the debugger and check up your intermediate number with what should be expected.

—SA
 
Share this answer
 
Use this, will definitely work.

SQL
SELECT DATEADD(day,2,OrderDate) AS OrderPayDate
FROM Orders


Please mark as answer if helped.
 
Share this answer
 
Use DateTime.AddDays and DateTime.AddMonths methods..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900