#### I need the difference between two dates expressed as 4 years 3 mo.

```I need a way to subtract the difference between two dates and exprss the
difference in a format simular to 10 years 6 months 7 days.  Assume a start
date of 12/19/1943 and an end date of Today().  I have no trouble using
datedif to get the number of years as 61 years, months as 11.  I have now
idea of how to convert the total number of days between the two dates to the
correct number days.  sngNumDays = DateDiff("d", DateOne, Now) gives the
total number of days (22657).

My current Code:

Private Sub cmdAge_Click()
Dim DateOne As Date
Dim intYears As Integer
Dim intMonths As Integer
Dim sngNumDays As Single
Dim introw As Integer
For introw = 2 To 4                             '3 different dates are
entered on rows 2 through 4
DateOne = Cells(introw, 13).Value           'get the start date from
sngNumDays = DateDiff("d", DateOne, Now)    'total number of years
in the period
intYears = Int(sngNumDays / 365)
intMonths = DateDiff("m", DateOne, Now)     'months is total months
in the time period
intMonths = intMonths - (intYears * 12)     'convert to months
difference in the current year
sngNumDays = DateDiff("d", DateOne, Now)    'total number of days in
the period
Me.Unprotect
'print the results to the row and column on the spread sheet
Cells(introw, 14).Value = "   " & intYears & " Years " & intMonths &
" Months " & sngNumDays & " Days"
Me.Protect
Next
End Sub
```
 0
Dean1 (103)
12/1/2005 3:50:02 AM
excel.misc 78881 articles. 5 followers.

2 Replies
525 Views

Similar Articles

[PageSpeed] 28

```Hi,
Using the "Datedif" function try:
=DATEDIF(A1,TODAY(),"md")

HTH
JG

--
pinmaster
------------------------------------------------------------------------
pinmaster's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=6261

```
 0
12/1/2005 4:58:05 AM
```
"Dean" wrote:

> I need a way to subtract the difference between two dates and exprss the
> difference in a format simular to 10 years 6 months 7 days.  Assume a start
> date of 12/19/1943 and an end date of Today().  I have no trouble using
> datedif to get the number of years as 61 years, months as 11.  I have now
> idea of how to convert the total number of days between the two dates to the
> correct number days.  sngNumDays = DateDiff("d", DateOne, Now) gives the
> total number of days (22657).
>
> My current Code:
>
> Private Sub cmdAge_Click()
>     Dim DateOne As Date
>     Dim intYears As Integer
>     Dim intMonths As Integer
>     Dim sngNumDays As Single
>     Dim introw As Integer
>     For introw = 2 To 4                             '3 different dates are
> entered on rows 2 through 4
>         DateOne = Cells(introw, 13).Value           'get the start date from
>         sngNumDays = DateDiff("d", DateOne, Now)    'total number of years
> in the period
>         intYears = Int(sngNumDays / 365)
>         intMonths = DateDiff("m", DateOne, Now)     'months is total months
> in the time period
>         intMonths = intMonths - (intYears * 12)     'convert to months
> difference in the current year
>         sngNumDays = DateDiff("d", DateOne, Now)    'total number of days in
> the period
>         Me.Unprotect
>         'print the results to the row and column on the spread sheet
>         Cells(introw, 14).Value = "   " & intYears & " Years " & intMonths &
> " Months " & sngNumDays & " Days"
>         Me.Protect
>     Next
> End Sub

Hi Dean, You got lucky. I just read a solution to your problem on Chip
Pearsons website www.cpearson.com. I hope it helps. Apparently you can not do
it in VBA with the DateDiff function. Cheers, Ross.

Function Age(Date1 As Date, Date2 As Date) As String
Dim Y As Integer
Dim M As Integer
Dim D As Integer
Dim Temp1 As Date
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 > Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 > Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(date2), Month(date2), 0)) + D
End If
Age = Y & " years " & M & " months " & D & " days"
End Function

```
 0
Oz (16)
12/1/2005 5:11:03 AM

Similar Artilces:

Outlook Express Viewing Problem
I am working on a computer system with a strange issue: After two years of use, all of a sudden two days ago The e- mail subject, sender and date show fine, but the body of the message will not display [either in the preview pane or when opened individually]. Here is the system stats: Windows ME, Office 2000, Outlook Express v6.0, Fully patched. Here is what I have done: Virus scan, Ad-aware 6.0 scan Can anyone help? Hi - This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet Explorer and is a quite different program, despite it...

OWA Issue #3
Hello Logging into OWA is fine. But once Im in, the status area on the botttom left of the window says done with an error flag. I open it up and get: Internet Explorer Problems with this web page might prevent it from being displayed properly or functioning properly. Line: 15 Char: 30 Error: Object expected Code: 0 URL: https://my server/exchange/?Cmd=contents Has anyone seen this? What should I look for? How should I repair this? Thanks for any help. Thomas ...

Not sure if Excel can do what i need
Hello all, I am obviously a new user to excel. I have a psychological assessmen that needs to be computerised for ease of use in obtaining results. Here is what i would like to happen. I have 28 questions with fiv Likert scale options(0-4) for answers. Each question addresses 1 of different personality traits. So questions 1, 6, 8, 22 look at anger. Where as questions 2, 9, 28 look at happiness. What i would like is fo excel to group the answers and give me the total number for each trait. Then based on that number, give out a prewritten (which i would provide result of the assessment. ...

Need Min Value from Row and Heading Value that Corresponds to it.
I have a table that looks somewhat like this w/o the *'d headings: h1 h2 h3 h4 h5 h6 h7 *Min Price *Heading \$5.00 \$6.00 \$3.00 \$4.00 \$9.00 \$1.00 \$9.00 \$1.00 h6 \$3.00 \$6.00 \$8.00 \$65.00 \$9.00 \$2.00 \$4.00 \$2.00 h6 \$4.00 \$9.00 \$5.00 \$7.00 \$1.00 \$2.00 \$8.00 \$1.00 h5 \$9.00 \$7.00 \$6.00 \$3.00 \$9.00 \$8.00 \$2.00 \$2.00 h7 \$7.00 \$8.00 \$9.00 \$7.00 \$9.00 \$8.00 \$8.00 \$7.00 h1 I have several SKU's with various price contract/programs. I want to find the best price in one cell and the heading that would correspond to that cell in another. I was trying to do this with an expression ...

Excel need help
I have 2 columns a and b . a contains payment b contains balance. I have the entire col b with the formula. my ? is when the balance appearsin b it is in all the cells in that column.I only want it in the used ones, not the unused ones:( example \$270.00 16,730.00 \$270.00 16,460.00 \$100.00 16,360.00 \$300.00 16,060.00 \$270.00 15,790.00 15,790.00 15,790.00 15,790.00 15,790.00 15,790.00 this 15790.00 is in col b...not a...I want no bal in unused cells -- fiftieslady ------------------------------------------------------------------------ fiftieslady's Profile: http://www.excelforum.co...

Date shows as 01/01/00
We have a spreadsheet that we want to enter a date in a cell. I have changed the format to Date 03/01/01 format but no matter what I do, any date is converted to 01/01/00. I have tried inserting a column, copying to another spreadsheet, etc. I know this is probably simple, but it's driving me crazy. Help please. In an un-used cell enter: =TODAY() if this is not the correct date, then touch CNTRL-ALT-F9 on the keyboard post what happens. -- Gary''s Student "Kmagg" wrote: > We have a spreadsheet that we want to enter a date in a cell. I have changed > the...

How can I link 2 pages without using the actual sheet as a reference? In other words, can I have two sheets linked by Identifying the same exact names one on each sheet? ...

Excel newbie needs help from math wiz (poker related)
I want to create a Excel workbook that will help in specific poker situations. Short version: I want to be able to calculate how often my opponent will need to fold for an all-in raise to show a positive expectation. Explanation: In poker you can win a hand by having the best hand at the end OR getting your opponent to fold. A common situation comes up where you have a "drawing hand" and face a bet by your opponent. In this situation you know you are currently behind in the hand, but have a chance to win if you catch some of your "outs" (cards that will give you th...

HELP.....Setting up Outlook express again
I've just installed everything on my computer again and im having trouble with outlook express. its asking for my incoming and outgoing server names and i have no idea what they are or where i get them, so i can access or set my account up again. if anyone knows can they please help me thanks!!!! you can reach me at : bl182ink@hotmail.com Amanda Arbuckle what type of account? who is the email provider? have you checked their website for assistance? -- "Amanda" <bl182ink@hotmail.com> wrote in message news:A37A86BC-5E22-4B1F-B6E3-9459C70971C1@microsoft.com... > I...

Outlook express #286
> > when I click on a link on my e-mail via > > Outlook express, it should open the link right? > > it was doing so until yesterday. I've did a virus/spyware scan > > and nothing. this is a weird problem > > I have to copy & paste the link in my web browser. > > other wise it won't open it from outlook express. Try posting this in an Outlook Express news group - this is not one of them. Outlook is a part of Microsoft Office and is what this group supports. Outlook Express is a part of Internet Explorer and has its own news groups. You can a...

Macro help needed........
How do I sort a particular column in ascending order and change the pag setup to landscape and margins to 0.25 using a macro code ? does anyone have a macro code for this ????? -- Message posted from http://www.ExcelForum.com Hi you have already received some answers in your previous threads please don't multipost! -- Regards Frank Kabel Frankfurt, Germany > How do I sort a particular column in ascending order and change the > page setup to landscape and margins to 0.25 using a macro code ? > > does anyone have a macro code for this ?????? > > > --- > Me...

Date Format Conversion?
I have a tab delimited text file with a column of dates. I copied and pasted a selection of them below as a reference, there are in reality over 35,000 rows of these dates. These text dates must be converted to the following date format and saved back into a text file as such: mm/dd/yyyy That includes leading zeroes in months and dates. E.g. 01/01/1999 To complicate matters, I need to explain the process to others. Does anyone even know where I should begin? THANK YOU, - Chris +++++++++++++++++++++++++++ 9031989 8131990 9201989 1271990 10291989 1081990 3041990 10051989 4191990 10...

Need to test a mobo
I had a power surge about 3 weeks ago - lost a drive, now making ticking noises. I had another two drive that seem to work sporadically now. So, I thought it might have been my power supply. Bought a tester and found out that all seems well. Next, I bought a new hard drive and found that it was also acting up - making noises like whirring up and down (like the other drives I thought were dead). So I am starting to wonder if it is my mobo - but how can I test this out? I am using a dual boot - Win XP and Win 7 - both drives work and don't work. Up and down. Right now my Win7 ...

Migrating customers from CRM 3.0 to GP 9.0
Since the CRM <-> GP Connector was pulled with no release date in site, what is the procedure for migrating all our existing customers from CRM to Great Plaines? I can't believe we have to re-enter everyone and their contracts. Thanks, John I have been using Scribe software with great success for both Migration and Integration to GP 9.0 from MSCRM 3.0. I know it can be a little pricey but it does not need it's own server like biztalk did. Go to http://www.scribesoft.com for more information. Or you can contact me directly at bmeyer@cargas.com to get more information. -- ...

Help needed
is there anyway you can see what links to other workbooks are associated with the workbook you have open. The problem i am having is when i open the workbook in question a message appears and states "The workbook you opened contains automatic links to information in another workbook. do you want to update this workbook with changes made to the other workbook" Yes....... No. if i click No the workbook opens, however if i click Yes the workbook just hangs and i have to go into task manager to shut down the system. I can only assume that there is a problem with one of the links....

Need help on this....thanks
I have an Excel worksheet which stored a survey outcome of over 1200 members. There are over 30 questions in the survey and the first column captured the member ID. The problem is 3 of the survey questions that allow multiple answers, instead the answer for those three questions are captured in seperate column, the answers are stored in a single column and it makes it very difficult to analysis those result. As a result I created addittional columns depending on the total number of the answers available for that question and assign the result manually to that column. It is very time consuming ...

How to access Customer Due Date for current transaction
Hi Everyone ? I am looking to display payment due date on the invoice for my customer when the tender type is store account Currently I have 2 type of due date : 14 days and 30 days So for example if invoice date is today 1 Sept 2010. I need to print the due date as 15 Sept 2010 How can I access the customer account due date in receipt ? I tried Customer.AccountDueDateType and I got error "token not found" anyone has an idea ? Thank you, Regards, Joie ...

I need Help
I have a random popup that i cant stop,when it does come up it seems to know what i was looking at,like when i was looking for registry cleaner it popped up and showed me one,any help would be great. On Jan 22, 6:57=A0am, Larry <La...@discussions.microsoft.com> wrote: > I have a random popup that i cant stop,when it does come up it seems to k= now > what i was looking at,like when i was looking for registry cleaner it pop= ped > up and showed me one,any help would be great. To eliminate questions and guessing, please provide additional information about your sys...

How do you print ole objects.. Thanks lachanda -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-forms/200710/1 On Wed, 03 Oct 2007 18:13:40 GMT, "misschanda via AccessMonster.com" <u36612@uwe> wrote: >How do you print ole objects.. >Thanks >lachanda What *kind* of OLE objects? Many of them are binary blobs (such as programs) which are inherently not printable. More details please! John W. Vinson [MVP] ...

Stuck in review and need to be in design.
I am using Visio 2007. I need to complete the diagram that I have been working on and I hit the review key by mistake. How do I get back to the design screen? On Wed, 4 Nov 2009 16:14:01 -0800, cameron <cameron@discussions.microsoft.com> wrote: >I am using Visio 2007. I need to complete the diagram that I have been >working on and I hit the review key by mistake. How do I get back to the >design screen? menu Tools -> Track Markup and then close the Review window. -- Regards, Paul Herber, Sandrila Ltd. DFD/SSADM for Visio http://www.visio-dfd.sa...

Can't Access Links In Outlook or Outlook Express
I am using Outlook 2000 for my e-mail and until a few days ago could open links in my Outlook E-mail. This no longer works. When clicking on the html/url links nothing happens when using Outlook. I tried reinstalling but this did not help. Links will work however in SBC/Yahoo mail. I prefer Outlook. Can anyone help me? I am using XP Pro with 512 Gig Ram and a 80 Gig HD. Thanks in advance for any assistance. counsel2@sbcglobal.net <counsel2@sbcglobal.net> wrote: > I am using Outlook 2000 for my e-mail and until a few days ago could > open links in my Outlook E-mail. This...

Need Help Despertly!
I am in a desperate situation. I had to reformat my hard drive. Prior to do this, I copied my entire User Profile to another drive. I can now access my User Profile information from Windows Explorer. Now that I installed Microsoft Outlook, I do not see any of my Contacts. I need to restore my Contacts to the new Outlook installation. Again, I did save my entire "User Profile" from my previous installation of Windows 2000 Professional. I just do not know how to access my Contact information from Outlook that included addresses and phone numbers and such. Any help would be greatly appr...

Plug in needed
Looking for an Outlook plug in which, on reply to a e-mail, will:- a) allow selective quoting only, and b) not top quote. Anything around at all? Much to my horror (sorry guys) the Boss wants us to use Outofluck at work! -- On the carpool lane lane to Nirvana. John Phillips <flatulentdingo@deadspam.com> wrote: > Looking for an Outlook plug in which, on reply to a e-mail, will:- > > a) allow selective quoting only, and > > b) not top quote. > > Anything around at all? The best Outlook adjunct I've found for quote handling on replies is Outlook-Quotef...

Insurance Policies in Different Currencies
How do I set up Insurance Policies in different currencies ? I am using Money 2006 Deluxe and when I create a insurance policy, it takes the base currency as the default. Appreciate any help here. Thanks "sbmd2006user" <sbmd2006user@discussions.microsoft.com> wrote in message news:A342B0FB-5352-42E4-BB4D-3F755891436E@microsoft.com... > How do I set up Insurance Policies in different currencies ? > I am using Money 2006 Deluxe and when I create a insurance policy, it > takes > the base currency as the default. Money apparently lacks the capability you're ...

What is the Need for XSD in Application Blocks designing
Can anyone help in clearing my doubt Hi, There is a need for me to implement Application Blocks in my project, (Basically 3 tire), the project comprises of UIL, BLL,Business Entities, DAL.. When i saw the example programs from User Interface Application Block example, which is implementing the Business Layer part, Interface for BLL and Business Entity part where by i am not able to understand the real usage of XSD's and the autogenerated C#? Can anyone explain me what is the process flow behind this fuda in a simple terms. Thanks in Advance Jagadeesh ...