How to Convert date to month and year only in excel

In excel, how to get the month and year string from an excel date value. How to convert the dates including both date and time to text string, just only display as year and month. This post will guide you how to convert date to month and year value using Text Function in Microsoft Excel.

The Excel TEXT function converts a numeric value into text string with a specified format. You can convert all the standard number formats such as: dates, times, currency to Text string in excel.

The syntax of the TEXT function is as below:

= TEXT (value, Format code)

1. Convert date to month and year with Text Function

If you want to convert the date to month and year only, you can use “yyyymm” format code within the TEXT function in excel, so you can write down the below TEXT formula:

=TEXT(date,"yyyymm")
Convert date to month and year with Text Function 1

Assuming that you want to get the text string of month and year only from the date value: 12/1/2018 in Cell B1, then you can enter the following TEXT function into Cell C1.

In the above example, the TEXT function will apply the format code that you specified and returns a text string “201812” in Cell C1.

For more format codes in excel formatting, you can refer to the below table:

Format CodeDescriptionExamples
0only display digits in its place

 

#.00 – Forces the function to display two decimal places

=Text(34.234,”$##.00″)

 

result: $34.23

#Display the placeholder=Text(4.527,”#.##)

 

result: 4.53

.the position of Decimal Point=Text(342.2,”0.00″)

 

result: 342.20

dDay of the month or day of week

 

d- one or two digit number (1-31)

dd- two digit number (01-31)

ddd-abbreviated day of week (Mon to Sun)

dddd-full name of day of week(Monday to Sunnday)

=Text(TODAY(),”DDDD”)

 

result: Monday

mThe Month of the Year

 

m- one or two digit number

mm-two digit number

mmm-abbreviated month(Jan to Dec)

mmmm-full name of month(January to December))

=Text(TODAY(),”MM/DD/YY”)

 

result:11/06/17

yyear

 

yy-two digit representation of year(e.g.01,17)

yyyy-four digit representation of year(e.g. 2001,2017)

=Text(TODAY(),”MM/DD/YY”)

 

result:11/06/17

hHour

 

h-one or two digit number (e.g. 1,23)

hh-two digit number (e.g. 01,23)

=Text(14:16,”hh:mm”)

 

result: 14:16

mMinute

 

m-one or two digit representation (e.g. 1,59)

mm-two digit representation (e.g. 01,59)

=Text(14:16,”hh:mm”)

 

result: 14:16

sSecond

 

s-one or two digit representation (e.g. 1,59)

ss=two digit representation (e.g. 01,59)

 

2. Convert date to month and year with Format Cell option

If you just want to display a date from 12/1/2018 to “201812” in cell B1, you do not need a formula, just refer to the following steps:

1# selected the cells you want to display a date with the year and month.

Convert date to month name 1

2# right click on the selected cells and click on “Format cells…”

3# Select “Custom” under “Number” tab, then type the custom format “yyyymm”in type.

Convert date to month and year with Text Function2

4# you will see that the date value is converted to month and year.

Convert date to month and year with Text Function2

3. Convert date to month and year Using VBA Code

Let’s unravel the third method—a more advanced approach involving VBA code.

Press Alt + F11 to open the Visual Basic for Applications (VBA) editor.

Insert a new module by right-clicking on any item in the Project Explorer, selecting “Insert,” and then choosing “Module.”

Copy and paste the following VBA code into the module:

Function ConvertToMonthYear(inputDate As Date) As String
    ConvertToMonthYear = Format(inputDate, "yyyymm")
End Function

Close the VBA editor. In a cell, enter the formula:

=ConvertToMonthYear(B1)

Press Enter to apply the formula. The result will display the month and year in the desired format.

4. Video: Convert date to month and year

This Excel video tutorial where we explore three efficient methods to convert dates to month and year format. In the first method, we’ll utilize the Text function. The second method involves the Format Cell feature. Finally, we’ll delve into VBA, offering a more dynamic solution.

5. Related Formulas

  • Excel Convert numbers to Text
    The Text function will accept a numeric value as the first argument, then based on the format code in the second argument to convert the number to text. You can convert all the standard number formats such as: dates, times, currency to Text string in excel.…
  • Convert date to month name with Text Function
    If you want to convert the date to a month name, you can use the TEXT function with a specified format code like “mmm”in excel.  You can try to run the following TEXT formula:=TEXT(B1,”mmm”)
  • Convert Date to text with Text Function in Excel
    you can use TEXT function in excel to convert dates to text in a specific format code. For example, The TEXT function can use the following patterns, like as: “mm/dd/yyyy”, “yyyy/mm/dd”, etc.

Related Functions

  • Excel Text function
    The Excel TEXT function converts a numeric value into text string with a specified format. The TEXT function is a build-in function in Microsoft Excel and it is categorized as a Text Function. The syntax of the TEXT function is as below: = TEXT (value, Format code)…

Leave a Reply