Calculating difference between 2 dates - Programmers Heaven

Howdy, Stranger!

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

Categories

Calculating difference between 2 dates

Victor77Victor77 Posts: 3Member
Greetings!

Happy New Year & Happy Sunday!

I need help in calculating the difference between 2 dates (the result should be like "1 year, 2 months and 15 days"). I am building an application for my team to show their tenure in the organization (LIVE TENURE FROM THE DATE OF HIRE TILL NOW). I have the formula in EXCEL but I am not able to get it converted into Visual Basic (I am only a beginner).

[size=4][b][color=Red]I am using Visual Basic 6.0 along with ADO connection.[/color][/b][/size]

The formula in Excel is "=YEAR(TODAY())-YEAR(E337)-IF(OR(MONTH(TODAY())=DAY(E337)),12,IF(AND(MONTH(TODAY())>MONTH(E337),DAY(TODAY())<DAY(E337)),-1)))&" months, "&TODAY()-DATE(YEAR(TODAY()),MONTH(TODAY())-IF(DAY(TODAY())<DAY(E337),1,0),DAY(E337))&" days""

I need this to be completed very soon and I appreciate any help that I can get on this question.

Looking forward to hear from you,

Thank You,

Venugopal

Comments

  • Termc1224Termc1224 Posts: 84Member
    use datediff function
    Datediff(interval, date1, date2)
    interval values as follow
    yyyy Year
    q Quarter
    m Month
    y Day of year
    d Day
    w Weekday
    ww Week of year
    h Hour
    n Minute
    s Second
    sample
    DateDiff("d", Now, theDate)



    : Greetings!
    :
    : Happy New Year & Happy Sunday!
    :
    : I need help in calculating the difference between 2 dates (the
    : result should be like "1 year, 2 months and 15 days"). I am building
    : an application for my team to show their tenure in the organization
    : (LIVE TENURE FROM THE DATE OF HIRE TILL NOW). I have the formula in
    : EXCEL but I am not able to get it converted into Visual Basic (I am
    : only a beginner).
    :
    : [size=4][b][color=Red]I am using Visual Basic 6.0 along with ADO
    : connection.[/color][/b][/size]
    :
    : The formula in Excel is
    : "=YEAR(TODAY())-YEAR(E337)-IF(OR(MONTH(TODAY())
    : =DAY(E337)),12,IF(AND(MONTH(TODAY())>MONTH(E337),DAY(TODAY())<DAY(E33
    : 7)),-1)))&" months,
    : "&TODAY()-DATE(YEAR(TODAY()),MONTH(TODAY())-IF(DAY(TODAY())<DAY(E337)
    : ,1,0),DAY(E337))&" days""
    :
    : I need this to be completed very soon and I appreciate any help that
    : I can get on this question.
    :
    : Looking forward to hear from you,
    :
    : Thank You,
    :
    : Venugopal
    :

    I'm the best there is,
    the best there was,
    and the best there ever will be.
    hahahahaha lolz :)
Sign In or Register to comment.