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

omairhe

Well-known Member
Joined
Mar 26, 2009
Messages
2,018
Office Version
  1. 2019
Platform
  1. Windows
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.

RossTattersall

New Member
Joined
Jun 18, 2019
Messages
22
The above response will be fine for display purposes but won't actually be date.

Instead try;

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!)
 
Solution

Forum statistics

Threads
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.
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