Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365. 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: Proper Comparisons for Dates in Merge Fields.

Proper Comparisons for Dates in Merge Fields

Written by Allen Wyatt (last updated February 7, 2026)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365


Volker is having a problem comparing dates in a merge field. His database contains a Birthdate field, which (obviously) contains a birth date for each person in the database. As he merges each record, he wants to compare the Birthdate field to a reference date, and then take some action based on the result. The logic he is attempting to use looks like this:

{IF {MERGEFIELD Birthdate} > "02/26/1996" "Under 30" "Over 30"}

The problem is that the comparison doesn't work properly; it doesn't return consistent results. In most cases, Word is doing a text comparison, not a true date comparison. That means you need to make sure that both values being compared are in the same, consistent format.

One possible solution is to use a format switch in the merge field, in the following manner:

{IF {MERGEFIELD Birthdate \@ "MM/dd/yyyy"} > "02/26/1996" "Under 30" "Over 30"}

This puts the incoming information into a comparable format. The results you get from this approach may depend, however, on characteristics of the data source, independent of Word.

In many cases, you'll get the best results by putting the dates into a year-first, no-separator format (so that a text comparison behaves the same as a date comparison). For instance:

{IF {MERGEFIELD Birthdate \@ "yyyyMMdd"} > "19960226" "Under 30" "Over 30"}

If you need a more explicit comparison, you can use the COMPARE field to compare the two values (again, after you format them consistently). This example compares the Birthdate to the same reference date:

{IF {COMPARE {MERGEFIELD Birthdate \@ "yyyyMMdd"} "19960226"} = 1 "Under 30" "Over 30"}

You can even compare to the current date by using the DATE field, like this:

{IF {COMPARE {MERGEFIELD Birthdate \@ "yyyyMMdd"} {DATE \@ "yyyyMMdd"}} = 1 "Date Is Later" "Date Is Earlier"}

If the comparison still yields inconsistent results, then the only solution may be to do a mathematical conversion on the date (actually, on both Birthdate and the reference date) so that you have an actual numeric comparison. You can do this by converting the date into a Julian value, which requires a very complex merge field, like the one shown here:

{IF {QUOTE {SET a{=INT((14-{MERGEFIELD BIRTHDATE \@ M})/12)}}
{SET b{={MERGEFIELD BIRTHDATE \@ yyyy}+4800-a}}
{SET c{={MERGEFIELD BIRTHDATE \@ M}+12*a-3}}
{SET d{MERGEFIELD BIRTHDATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}
{jd \#,0}} > 2,443,056 "over 30" "under30"}

Such an approach may look intimidating, but is just the brute-force method necessary for some instances.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (9995) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Proper Comparisons for Dates in Merge Fields.

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

Merging Only a Date from Access

When you are merging data from an Access database, you may get more information than you want, especially when it comes ...

Discover More

Rejecting Changes in a Document

When a group of people edits a document with Track Changes turned on, it can be tempting for one of the editors to use ...

Discover More

Copying Files or Folders

A common operation within Windows is to copy files and folders from one location to another. Here are the two major ways ...

Discover More

Discover the Power of Microsoft Office This beginner-friendly guide reveals the expert tips and strategies you need to skyrocket your productivity and use Office 365 like a pro. Mastering software like Word, Excel, and PowerPoint is essential to be more efficient and advance your career. Simple lessons guide you through every step, providing the knowledge you need to get started. Check out Microsoft Office 365 For Beginners today!

More WordTips (ribbon)

Attaching Specific Files to Mail-Merge E-Mail Messages

Want to add attachments to each e-mail message created in a mail merge? Word doesn't include the capability to do this, ...

Discover More

Merging to Individual Files

The mail-merge feature in Word is a fast, easy way to create form letters addressed to many different people. Sometimes, ...

Discover More

Merging and Printing

When you merge information into a document, Word provides two different ways you can create your output. Here's an ...

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 more than 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.