Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 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.
by Allen Wyatt
(last updated April 20, 2019)
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:
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 Office 365. You can find a version of this tip for the older menu interface of Excel here: Converting Mainframe Date Formats.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
When entering times in a worksheet, you may have a need to round whatever you enter to the nearest 15-minute increment. ...Discover More
Many businesses need to know when the last business day of the month occurs. This tip discusses several ways you can ...Discover More
Enter information into a worksheet, and you come to anticipate (and count on) how Excel will interpret that information ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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.