Format Dates problem

Itaybill

New Member
Joined
May 19, 2009
Messages
38
Hi

I import text files into one excel file, but a certain column called "date" is quite problematic: the dates are in american format (MM/DD/YY) and i need to convert them to UK Format (DD/MM/YY). i managed to solve this by using a formula, but the problem is solved only some of the dates (example below - only for the ones that the day is larger than 12). also, i the excel the dates that the day is below 12 are written akwared (aligned to the side)

Date Corrected
02/22/11 22/02/11
02/23/11 23/02/11
02/24/11 24/02/11
02/28/11 28/02/11
03/01/2011 #Value!
03/02/2011 #Value!
03/03/2011 #Value!
03/08/2011 #Value!
03/09/2011 #Value!


the formula is:=DATEVALUE(MID(D2,4,2)&"/"&LEFT(D2,2)&"/"&RIGHT(D2,2))


Thanks!

Itay
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try something like this...

Code:
=IF(ISTEXT(D2), DATEVALUE(MID(D2,4,2)&"/"&LEFT(D2,2)&"/"&RIGHT(D2,2)), DATE(YEAR(D2),DAY(D2),MONTH(D2)))
 
Upvote 0
it works! thanks!

by the way, do you have any idea why it happens? in the text file, all the dates seems identical...
 
Upvote 0
Another option (Which worked for me)
Code:
Sub DateChangeUKtoUS()
Dim i As Integer
x = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To x
        Range("C" & i).Value = Format(Range("A" & i).Value, "mm/dd/yyyy")
    Next i
End Sub

Sub DateChangeUStoUK()
Dim i As Integer
x = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To x
        Range("C" & i).Value = Format(Range("A" & i).Value, "dd/mm/yyyy")
    Next i
End Sub

Does US to UK or vice-versa,

Cheers
Colin
 
Upvote 0
it works! thanks!

by the way, do you have any idea why it happens? in the text file, all the dates seems identical...
When the day is 12 or less in the imported date, Excel will try to use the day value as the month and interpret it as a date even though it is not the date you want. When the day is greater than 12,Excel cannot use the day as the month value because month values are not greater than 12. So that imported date remains as text. It is not interpreted as a date.

The new formula checks if the value is text. If it is, it parses the text into a date. If it is not text but rather just a misinterpreted date, it swaps the day and month.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top