# How to convert date from a hyphen "-" to an underscore "_"

#### omairhe

##### Well-known Member
How do I convert a formula that outputs month number and year joined together with each other using a hyphen and change that into underscore. The formula I have is important because when last month of the year is reached, the plus 1 then gives me next year's date e.g. 01-2022

A3 = TEXT(DATE(A2,A1+1,1),"mm-yyyy")

A1 = 01
A2 = 2021

Current output = 01-2021

Desired output = 01_2021

Thanks.

### Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

maybe
Book1
A
101
22021
301_2021
Sheet1
Cell Formulas
RangeFormula
A3A3=A1&"_"&A2

#### RossTattersall

##### New Member
The above response will be fine for display purposes but won't actually be date.

A3= TEXT(DATE(A2,A1+1,1),"mm\_yyyy")

Without the slash Excel turns _ into a space in text formats for some reason (despite spaces being completely acceptable in formats!)

##### Well-known Member
Hi Omairhe,

Try `=TEXT(DATE(A2,A1+1,1),"mm\_yyyy")`

Bravo!!

#### Dave Patton

##### Well-known Member
It may depend on if you require text or a date.

T202101a.xlsm
ABCD
101Format
22021General 7-Jan-21
301_2021=A1&"_"&A201_2021TRUE
401_2021Text01_2021TRUE
501_2021Date custom format as mm\_yyyy44197FALSE
6
4d
Cell Formulas
RangeFormula
B3B3=Gf(A3)
C3:C5C3=A3
D3:D5D3=A3>\$D\$2
A3A3=A1&"_"&A2
A4A4=TEXT(DATE(A2,A1,1),"mm\_yyyy")
A5A5=DATE(A2,A1,1)

Replies
11
Views
154
Replies
3
Views
89
Replies
6
Views
181
Replies
2
Views
218
Replies
2
Views
152

1,136,641
Messages
5,676,954
Members
419,663
Latest member
Xbox_360

### 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