Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Changing the Format of Existing Dates.

Changing the Format of Existing Dates

Written by Allen Wyatt (last updated August 20, 2020)
This tip applies to Word 2007 and 2010


11

Aileen works with a lot of documents that have the date in a numeric format, such as 9/22/12. She needs to convert these dates to a different format, specifically September 22, 2012. She wonders if there is an easy way to make the change without needing to retype each date.

The answer depends, in large part, on the nature of the date you are changing. Dates in a Word document can either be straight text or a field. You can tell if the date is a field by simply moving the insertion point somewhere inside the date. If it is a field, then the entire date should be shaded in light gray once the insertion point is within the date.

If the date is a field, then you can right-click on the date and choose Edit Field from the resulting Context menu. You can then modify the field, including selecting a different date format in the Field Properties list.

If the date is regular text (not a field), then you need to look to a different solution. It is possible to go through the document and manually retype all the dates, but Aileen already found out that such an approach is tedious. This is where a macro can come in handy: to cure the tedium by programmatically doing what you would otherwise do by hand.

The following macro will step through a document, searching for all dates in the format m/d/yyyy. (There can be either one or two digits for either the month or day, but must be four digits for the year.) If a date matching this pattern is found, it is converted to the format mmmm d, yyyy.

Sub GetDateAndReplace()
    Dim FoundOne As Boolean

    Selection.HomeKey Unit:=wdStory, Extend:=wdMove
    FoundOne = True ' loop at least once

    Do While FoundOne ' loop until no date is found
        With Selection.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"
            .Format = True
            .Forward = True
            .MatchWildcards = True
        End With

        Selection.Find.Execute Replace:=wdReplaceNone

        ' check the find to be sure it's a date
        If IsDate(Selection.Text) Then
            Selection.Text = Format(Selection.Text, "mmmm d, yyyy")
            Selection.Collapse wdCollapseEnd
        Else ' not a date - end loop
            FoundOne = False
        End If
    Loop
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12197) applies to Microsoft Word 2007 and 2010. You can find a version of this tip for the older menu interface of Word here: Changing the Format of Existing Dates.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Excellent XML Resource Available

Where to get more information on XML.

Discover More

Clean Up Your Macro List

Got a workbook cluttered with all sorts of macros? Delete them and you'll make your workbook easier to manage.

Discover More

Resizing Your Table

Need to make your table a different size? It's easy to do, using the same general technique you use when resizing a ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Creating a Document Font List

If you want a list of all the fonts used in a document, the answer isn't as simple as you may think. This tip uses macros ...

Discover More

Changing Directories in a Macro

When a macro works with files, it often has to change between different directories on your disk drive. This is done ...

Discover More

Counting Open Document Windows

When creating macros, it is sometimes necessary to know how many documents are open in Word. This is relatively easy to ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is five minus 5?

2021-02-03 03:09:12

M A Manoj

Would there be something similar for quite the opposite, changing month, d, yyyy format to mm/dd/yy format?


2020-04-13 20:23:57

C

Just wanted to drop you a line to say thanks, I've used this macro successfully and it is quite helpful.


2018-11-12 16:32:09

Allen

Marcus: Make sure it is "None" at the end, not "Non."

-Allen


2018-11-08 07:19:15

MARCHUS YW WAGENBERG

Hi, I've tried to enter macros in Word 2016, but I'm getting "debug" issues with this phrase "Selection.Find.Execute Replace: = wdReplaceNon" Error 5560?


2018-06-26 02:49:19

Leanne

I really like this macro however i have the issue with change the american format 05/08/2018 (8th May 2018) changing to the correct format. it changes those with the higher dd but does not convert the earlier ones the same way.

Date of discharge:05/19/2018
Date of discharge:May 19, 2018

Date of discharge:05/08/2018
Date of discharge:August 5, 2018
Should be May 8, 2018

any help would be appreciated..


2018-06-25 23:03:11

Leanne

I really like this macro however i have the issue with change the american format 05/08/2018 (8th May 2018) changing to the correct format. it changes those with the higher dd but does not convert the earlier ones the same way.

Date of discharge:05/19/2018
Date of discharge:May 19, 2018

Date of discharge:05/08/2018
Date of discharge:August 5, 2018
Should be May 8, 2018

any help would be appreciated..


2018-01-11 04:33:11

Rob B

This is a brilliant macro, thanks.
It would help, though, if you could also explain the Pattern Match instructions steps, which seem quite complex.

Also, how does one convert dates like December 7, 2013 to 7 December 2013?


2017-02-04 00:37:25

sunwukong

I need to convert dates like December 7, 2013 to 20131207.


2017-02-04 00:36:00

sunwukong

I have the opposite problem. I need to convert dates like Deceember 7, 2013 to 20121207.


2016-02-12 17:10:36

Nikaya

Thanks, this worked great!

One potential problem - it stops completely if it runs into a date format that is not a date. It freezes for review, but I can't get it to resume unless I delete or reformat the culprit (such as 15/92/82). I don't anticipate running into this often, if ever, but I want to be prepared. Any suggestions? Maybe a prompt box to move to next?

I also changed:

.Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"

to:

.Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{2,4})"

in case a document has a dd/mm/yyyy format or a mix of dd/mm/yy and dd/mm/yyyy. Worked like a charm! :)


2015-07-07 14:10:29

Terry Pennell

In Word 2007, this Sub returned an error message. "The Find What text contains a Pattern Match expression which is not valid."

The routine ran without error and produced the intended results after I replaced the following line:

.Text = "([0-9]{1,2})[/]([0-9]{1,2})[/]([0-9]{4})"

With the following line:

.Text = "(<*>)/(<*>)/(<*>)"




This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.