ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   add leading 0 for single month return (https://www.excelbanter.com/excel-discussion-misc-queries/182219-add-leading-0-single-month-return.html)

Cam

add leading 0 for single month return
 
Hello,

I got a date field and calculate the month out of that date field using
=MONTH(Date) and it returns the month,for example 6/15/07 (return 6) and
11/20/07 (11),
how do I tell it to return 06 instead of 6 on the single digit month.

ExcelBanter AI

Answer: add leading 0 for single month return
 
Adding a Leading Zero to a Single Digit Month in Excel

To add a leading zero to a single digit month in Excel, you can use the
Code:

TEXT
function. Here's how:
  1. Start by entering your original formula to calculate the month, for example:
    Code:

    =MONTH(Date)
  2. Next, wrap the formula in the
    Code:

    TEXT
    function, like this:
    Code:

    =TEXT(MONTH(Date),"00")
  3. The
    Code:

    "00"
    inside the
    Code:

    TEXT
    function tells Excel to format the month with two digits, adding a leading zero if necessary.
  4. Press Enter to apply the formula and you should now see the month with a leading zero for single digit months.

For example, if your original formula returned 6 for the date 6/15/07, the new formula with the
Code:

TEXT
function will return 06 instead.

I hope that helps!

Ron Coderre

add leading 0 for single month return
 
If you only want to *display* the leading zero
try this:

From the Excel Main Menu:
<format<cells<number tab
Category: Custom
Type: 00
Click the [OK] button

Alternatively, this formula actually creates a 2-character *text* string:
=TEXT(MONTH(A1),"00")

Does that help?
Post back if you have more questions.
--------------------------

Regards,

Ron
Microsoft MVP (Excel)
(XL2003, Win XP)

"Cam" wrote in message
...
Hello,

I got a date field and calculate the month out of that date field using
=MONTH(Date) and it returns the month,for example 6/15/07 (return 6) and
11/20/07 (11),
how do I tell it to return 06 instead of 6 on the single digit month.





All times are GMT +1. The time now is 10:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com