Date Problem,its urent

I am just trying to find the TO date.TO date is actually 5 years (or 4 yrs 11 months 30 days)to the "From "Date

ex:1/jan/2000 will give 30/Dec/2004

07/jan/1998 will give 05/jan/2003

how can get this value
i tried dateadd function but not gettinng correct result.i dont know is it because of leap year.can u give me a solution

Comments

  • seancampbellseancampbell Pennsylvania, USA
    To add that amount of time to your Date Object use:

    Dim Date1 As Date = CDate("1/1/2000")
    Date1 = Date1.AddYears(4)
    Date1 = Date1.AddMonths(11)
    Date1 = Date1.AddDays(30)


    If your result is off by 1 or 2 days, then you are probably right that a Leap year is messing with your result.

    View the "psuedo code" section of this article: http://en.wikipedia.org/wiki/Leap_year to get an idea on how you can check if a year is a leap year. You can add more days in cases that you pass over a Leap year...

    NOTE: If you do (Date.AddYear()) it will add 365 days on non-leap years and 366 days on leap years...
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion