
Tips.Net > ExcelTips Home > Worksheet Functions > Date and Time Functions > Parsing Non-Standard Date Formats
Summary: If you import information into a worksheet from a different program, you may be surprised when Excel doesn’t parse the dates correctly. This tip describes some ways in which you can help Excel to make sense of the imported data. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)
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 02.01.07 or 2.1.2007, 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 2.1.2007 to 2/1/2007, 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 02.01.07 (February 1, 2007), and your system would interpret this as January 2, 2007, then the easiest way is to separate the date into individual components, and then put them back together. Follow these general steps:
=DATE(C1,A1,B1)
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
Tip #3191 applies to Microsoft Excel versions: 97 2000 2002 2003 2007
Save Time! ExcelTips has been published weekly since late 1998. Past issues of ExcelTips are available in convenient ExcelTips archives. Have your own enhanced archive of ExcelTips at your fingertips, available to use at any time!
Check out ExcelTips Archives today!
Add power to your purpose with Excel. A comprehensive 500+ page e-book explains everything you need to know about macros. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site