Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Parsing Non-Standard Date Formats.
by Allen Wyatt
(last updated July 11, 2015)
Bill is faced with the challenge of importing data into Excel that was originally created in other applications. The problem is that the data contains lots of dates, but they are in a format that Excel doesn't understand. For instance, the dates may be in the format 01.15.11 or 1.15.2011, neither of which is treated as a date by Excel. Bill wants to know how to convert the non-standard dates to a date format that Excel understands.
If the dates are in the same sequence format that you use in your regional settings, then converting is a snap. For instance, if your regional settings use the date format MDY (month followed by day followed by year), and the date you are importing is in the same format, then you can simply select the cells and replace the periods with a slash. When Excel changes 1.15.2011 to 1/15/2011, it automatically parses the result as a date.
If the format you are importing doesn't match your regional settings, then you need to shuffle around the date into the same format. For instance, if the date you are importing is 01.10.11 (January 10, 2011), and your system would interpret this as October 1, 2011, then the easiest way is to separate the date into individual components, and then put them back together. Follow these general steps:
Another solution is to simply use a macro to do the conversion. The following is a user-defined function that takes the non-standard date and converts it to a properly formatted date value. The macro also switches around the position of the month and day, as done in the Text to Columns technique.
Public Function Convert_Date(A As String) As Date Dim K As Long Dim K1 As Long Dim K2 As Long K = Len(A) K1 = InStr(1, A, ".") K2 = InStr(K1 + 1, A, ".") Convert_Date = DateSerial(Val(Mid(A, K2 + 1, _ K - K2 + 1)), Val(Mid(A, K1 + 1, K2 - K1)), _ Val(Mid(A, 1, K1 - 1))) End Function
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3191) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Parsing Non-Standard 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!
The NETWORKDAYS worksheet function can be used to easily determine the number of work days (Monday through Friday) within a ...Discover More
Need to print an elapsed date in a strange format? It's easier to do than may appear at first glance. Here's a discussion on ...Discover More
Excel allows you to perform quite a few operations using dates in your worksheet. Sometimes, however, the answer may not be ...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 menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.