MM/DD/YYYY-YYYY=? Date Subtraction

jiminoregon

New Member
Joined
Apr 27, 2008
Messages
30
This should be easy...but apparently I'm Excel challenged...

I have a date box that displays MM/DD/YYYY. I have another box that displays only the year.

I'm trying to take MM/DD/YYYY-YYYY=# of years.

For example 03/28/2009-2005=4 years.

2 hours into this I've been able to come up with everything but the right answer...any help appreciated.

Thanks,

Jim
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
VBA solution for string variables:
Rich (BB code):
<font face=Courier New>
Sub Test()
  Dim txt1, txt2
  txt1 = "03/28/2009"
  txt2 = "2005"
  MsgBox Val(Split(txt1, "/")(2)) - Val(txt2)
End Sub</FONT>

For date (not string) cells try formula:
=YEAR(A1)-A2
where A1 is the 03/28/2009 date value
A2 is the 2005 numeric value
 
Last edited:
Upvote 0
VBA solution for string variables:
Rich (BB code):

Sub Test()
  Dim txt1, txt2
  txt1 = "03/28/2009"
  txt2 = "2005"
  MsgBox Val(Split(txt1, "/")(2)) - Val(txt2)
End Sub

For date (not string) cells try formula:
=YEAR(A1)-A2
where A1 is the 03/28/2009 date value
A2 is the 2005 numeric value

Thank you so much... =YEAR(A1)-A2 works perfectly!

Jim
 
Upvote 0

Forum statistics

Threads
1,214,627
Messages
6,120,610
Members
448,973
Latest member
ChristineC

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top