# Date calculation

#### KGee

##### Well-known Member
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
If year 2 is a string try

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

#### KGee

##### Well-known Member
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

Thanks again.

Replies
24
Views
4K
Replies
6
Views
1K
Replies
3
Views
632
Replies
3
Views
620
Replies
8
Views
516

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.

### Which adblocker are you using?

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

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