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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
If year 2 is a string try

Code:
year1 = "09"
If year1 = "09" Then
    year2 = Format(year1 - 1, "00")
End If
 
Upvote 0
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,214,611
Messages
6,120,509
Members
448,967
Latest member
screechyboy79

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