Date calculation

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
537
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a date in dd-mmm-yy format. I extracted the two digit year and need to increase or decrease by one year. How can I use the code below to return the two digit year?
Code:
If year1 = "09" Then
    year2 = year1 - 1
End If
I realize I can add a check to see if the first digit is a 0 and take the appropriate action or change the date format to a four digit year before calculating, but I'm wondering if there is simpler way to do it, like using the format function or similar.

Thanks - Kevin
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
If year 2 is a string try

Code:
year1 = "09"
If year1 = "09" Then
    year2 = Format(year1 - 1, "00")
End If
 
Upvote 0

KGee

Well-known Member
Joined
Nov 26, 2008
Messages
537
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Thanks once again for your help VoG. I probably should have been able to figure that oout on my own. At least I was on the right track :biggrin:

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,191,124
Messages
5,984,784
Members
439,911
Latest member
dk73

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
Top