Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Converting Mainframe Date Formats.

Converting Mainframe Date Formats

Written by Allen Wyatt (last updated January 2, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Some of the data you work with in Excel may start as output from large systems in your office. Sometimes the date formats used by the large systems may be completely misunderstood by Excel. For instance, the output may provide dates in the format yyyydddtttt, where yyyy is the year, ddd is the ordinal day of the year (1 through 366), and tttt is the time based on a 24-hour clock. At first glance, you may not know how to convert such a date to something that Excel can use.

There are many ways that a solution could be approached. Perhaps the best formula, however, is the following:

=DATE(LEFT(A1,4),1,1)+MID(A1,5,3)-1+TIME(MID(A1,8,2),RIGHT(A1,2),0)

This formula first figures out the date serial number for January 1 of the specified year, then adds the correct number of days to that date. The formula then calculates the right time based on what is provided.

When a formula like this is invoked, the result is a date serial number. This means that the cell still needs to be formatted to display a date format.

This approach will work just fine, provided that the information that you start with makes sense. For instance, you will always get the expected result if ddd really is within the range of 1 through 366, or if tttt is a properly formatted 24-hour representation of time. If you anticipate original data that could be out of bounds, then the best solution is to create a custom function (using a macro) that will tear apart the original data and check the values provided for each portion. If the data is out of bounds, the function could return an error value that would be easily detected within the worksheet.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9241) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Converting Mainframe Date Formats.

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

Cannot Open Multiple Word Documents

What are you to do if you try to open a document and Word automatically closes your previous document? Word is not ...

Discover More

Saving a Preview with Your Template

Templates provide a collection of styles and boilerplate for new documents. Selecting the right template by filename only ...

Discover More

Using Mail Merge to Complete Documents

Mail merge can be used to put together groups of documents that rely on common information. This tip shows how mail merge ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Finding the Previous Work Day

Simple math will tell you what the previous day is (just subtract 1 from today's date). What if you want to know the date ...

Discover More

Calculating the Last Day in a Week Number

Given a particular week number for a year, you may want to figure out the date of the last day in that week. There is no ...

Discover More

Returning Nothing If Two Values are Empty

Excel includes a large number of functions that can be used in evaluating the data in a worksheet. In this tip you learn ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, 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 6 + 5?

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 Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, 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.