Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Calculating difference between 2 dates Posted by Victor77 on 6 Jan 2008 at 6:18 AM
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).

I am using Visual Basic 6.0 along with ADO connection.

The formula in Excel is "=YEAR(TODAY())-YEAR(E337)-IF(OR(MONTH(TODAY())<MONTH(E337),AND(MONTH(TODAY())=MONTH(E337),DAY(TODAY())<DAY(E337))),1,0)&" years, "&MONTH(TODAY())-MONTH(E337)+IF(AND(MONTH(TODAY())<=MONTH(E337),DAY(TODAY())<DAY(E337)),11,IF(AND(MONTH(TODAY())<MONTH(E337),DAY(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
Report
Re: Calculating difference between 2 dates Posted by Termc1224 on 8 Jan 2008 at 11:33 PM
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).
:
: I am using Visual Basic 6.0 along with ADO
: connection.

:
: The formula in Excel is
: "=YEAR(TODAY())-YEAR(E337)-IF(OR(MONTH(TODAY())<MONTH(E337),AND(MONTH
: (TODAY())=MONTH(E337),DAY(TODAY())<DAY(E337))),1,0)&" years,
: "&MONTH(TODAY())-MONTH(E337)+IF(AND(MONTH(TODAY())<=MONTH(E337),DAY(T
: ODAY())<DAY(E337)),11,IF(AND(MONTH(TODAY())<MONTH(E337),DAY(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 :)



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.