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

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

# Calculating difference between 2 dates

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

• 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