8

I have imported a CSV file with 2 long columns of dates. These dates are in the US format Aug/28/2013 and I want them to be in the standard UK dd/mm/yyyy format.

I have tried formatting the cells as US dates and then converting them to number-only formats, and various other permutations within the Date format box, but with no success.

Can anyone rid me of these awful US dates please?

rolve
  • 10,083
  • 4
  • 55
  • 75
Cara Murphy
  • 99
  • 1
  • 1
  • 2
  • You can filter the csv before importing in Excel with Powershell on Windows of (after ftp to *nix server) ksh/bash on *nix. – Walter A Dec 05 '14 at 10:33

11 Answers11

16

Another solution without using a formula:

  • Select the relevant columns
  • Choose Data → Text to Columns…
  • Select “Delimited” and click Next
  • Untick all delimiters and click Next
  • Select data column format “Date: MDY” and click Finish

The dates should now be converted to UK dates.

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
  • 2
    Am I the only one for whom this technique literally does nothing? – cbp Aug 10 '17 at 06:48
  • @cbp same for me - nothing changes – PeterX Mar 12 '18 at 23:04
  • I expect this may be dependent on system locale settings. The default selected option for me in the date format is "DMY" so I need to change the drop-down to match the actual format of the column. – cmbuckley Mar 13 '18 at 12:07
5

The problem is that a US date can parsed by Excel as a UK date when the day is less than 13. When this happens Excel converts it to the localized UK serial (date) number.

So 03/19/2014 is obviously a US date of the 19th of March. However 05/03/2014 is ambiguous so Excel parses it the local date format as the 5th of March, rather than the US 3rd of May. Any formula has to check if Excel has stored the US Date as a UK date. A UK date will be stored in Excel as a number.

=IF(ISNUMBER(A2),DATE(TEXT(A2,"yyyy"),TEXT(A2,"dd"),TEXT(A2,"mm")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2)))

(For a US date in cell A2 and PC date is dd/mm/yy).

If ISNUMBER is true, the US date looks like a UK date and Excel has serialized it as a number. So can format the date as text and back to a date again. Note day is passed to the month parameter of the first DATE function to perform the conversion. If ISNUMBER is false, its stored as a string as Excel doesn't convert a date string with >12 months. So use string functions to split it up for the DATE function.

Shevliaskovic
  • 1,562
  • 4
  • 26
  • 43
user3155533
  • 59
  • 1
  • 2
  • This formula will return an error when the day has only one digit (days from 1 to 9) and does not have the leading zero, as in that case it will extract also the slash along with the symbol. I've found a workaround by modifying the way the day value is extracted: `=IF(ISNUMBER(A2),DATE(TEXT(A2,"yyyy"),TEXT(A2,"dd"),TEXT(A2,"mm")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(LEFT(A2,FIND("/",A2,4)-1),FIND("/",A2)+1,LEN(A2))))` I've tested it and looks like it work in all possible cases. – Wayfarer Aug 02 '16 at 18:44
  • This didn't work for "9/26/1976 2:00:00 PM" - I got "270" as as result that formatted to "1900-09-26" – PeterX Mar 12 '18 at 23:07
2

I'm assuming that the date you received is formatted as text and that simply formatting it as date is not changing anything. You can run the following formula on the date:

=(MID(A1,FIND("/",A1)+1,FIND("/",A1,FIND("/",A1)+1)-FIND("/",A1)-1)&"-"&LEFT(A1,FIND("/",A1)-1)&"-"&RIGHT(A1,4))*1

If you get numbers, you just need to format it as dd/mm/yyyy and it should be good.

Jerry
  • 70,495
  • 13
  • 100
  • 144
1

I tried some of the other suggestions but none seemed to work for me. In my case I was importing US dates in the form M/d/yyyy hh:mm:ss. If you don't mind using some VBA in your spreadsheet then the following function did the job for me:

Public Function USDate(ds As Variant) As Variant
    Dim sp() As String
    Dim spt() As String
    Dim spt2() As String

    If ds = vbNullString Then
        USDate = ""
    ElseIf IsNumeric(ds) Then 
        ' Convert numeric US dates wrongly interpreted as UK i.e. 1/7/2017 as 7th January 2017
        USDate = DateSerial(Year(ds), Day(ds), Month(ds)) 
    Else
        sp = Split(ds, "/") ' split the date portion
        spt = Split(sp(2), " ") ' split the time from the year
        spt2 = Split(spt(1), ":") 'split the time hms

        USDate = DateSerial(spt(0), sp(0), sp(1)) + TimeSerial(spt2(0), spt2(1), spt2(2))
    End If
End Function

Thanks for https://stackoverflow.com/users/845584/peterx pointing out - you will need to create the function in a VBA code module to use this technique.

Simply use it in a spreadsheet formulae for example =USDate(A2)

user2486488
  • 91
  • 1
  • 8
  • I originally got a "#NAME?" error. You need to use it in a module as per here: https://stackoverflow.com/a/16296990/845584 – PeterX Mar 12 '18 at 23:27
0

Related to this, the below simply formula can be helpful for changing a date from

"MM/DD/YYYY"

into

"DD/MM/YYYY".

=VALUE(TEXT(B2,"mm/dd/yyyy"))
Horaciux
  • 6,322
  • 2
  • 22
  • 41
0

We can get best of both world with this more concise formula:

=IF(ISNUMBER(A2),VALUE(TEXT(A2,"mm/dd/yyyy")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2)))

Can't find anything shorter.

Boulebill
  • 9
  • 1
  • This formula will return an error when the day has only one digit (days from 1 to 9) and does not have the leading zero, as in that case it will extract also the slash along with the symbol. I've found a workaround by modifying the way the day value is extracted: `=IF(ISNUMBER(A2),VALUE(TEXT(A2,"mm/dd/yyyy")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(LEFT(A2,FIND("/",A2,4)-1),FIND("/",A2)+1,LEN(A2))))` I've tested it and looks like it work in all possible cases. – Wayfarer Aug 02 '16 at 18:45
  • As above, I get "270" for the American Date "9/26/1976 2:00:00 PM" – PeterX Mar 12 '18 at 23:09
0

There was one more issue for me, as somehow the raw data was supposed to be read as a number, but it did not. Hence, i updated the formula with 1 final case:

=IFERROR(IF(ISNUMBER(A2),VALUE(TEXT(A2,"mm/dd/yyyy")),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,2))),DATE(RIGHT(A2,4),LEFT(A2,FIND("/",A2)-1),MID(A2,FIND("/",A2)+1,1)))

w31hon9
  • 51
  • 5
0

This can be tricky when the dates in mixed format eg. UK and US in the same column. I have found an effective if inelegant solution:

Step1) Select the column containing the dates to be converted;

Step2) Format, Cells, Text;

Step3) Format, Cells, Date, US;

Step4) Data, Text to column, Next, Delimited, Next, delete all delimiters, Next, select format MDY;

Step5) Format, Cells, Date, UK.

Step4 had been suggested elsewhere, but that on it's own didn't do it for me. I am hoping to combine these steps into a macro but no success this far.

maren
  • 1
0

I couldn't get the most common answer to work, the process that worked for me was:

For date 10/04/2018 11:49:20, right-click cell and "Format Cells", "Number" tab and select "Custom" Category and then select mm/dd/yyyy hh:mm.

Matheus Lacerda
  • 5,983
  • 11
  • 29
  • 45
PuffTMD
  • 63
  • 9
  • This merely alters the way the date is displayed, not the way excel understands days/months – Cos Aug 22 '20 at 11:15
0

Assuming that you start with a string (and not an internal excel date number that is just formatted as US format - which is an easy fix), can someone tell me why this method doesn't work?

Use the DATEVALUE / TIMEVALUE functions to convert it into an excel internal formatted date number (You might need to MID() the string in case there are extra bits before or after).

Just make sure that your regional settings match the input date format (otherwise DATEVALUE will fail and you will get a #VALUE error).

Then set the cell format to display the way you want it (Custom format e.g. "dd/mm/yyyy hh:mm:ss").

If you also want to change the timezone, you can add on (hours/24) to the internal Excel excel formatted date number.

Roy
  • 1
  • 1
0

The above look impressively complex! Why any country should settle on a non-sequential date format escapes me! Say you have a US-format date (mm/dd/yy) in cell A1. To convert this to dd/mm/yy format as in the UK, just do:

=CONCATENATE(MID(A1,4,2),"/",MID(A1,1,2),"/",MID(A1,7,2)) 

This certainly works in LibreOffice and I hope also in Excel.

Peter Csala
  • 17,736
  • 16
  • 35
  • 75