Mixed Date Formats in the same Column

Status
Not open for further replies.

paulfitz320

Board Regular
Joined
Jan 6, 2007
Messages
126
Office Version
  1. 365
Platform
  1. Windows
I have a big spreadsheet, some 750000 rows.

In Column C I have dates.

Approximately half of the dates in this Column are in dd/mm/yyyy format, the other half in mm/dd/yyyy format, I think.

eg. 31/05/2012
then 01/06/2012 (appears as 06/01/2012 in the formula window)

Any help to get them ALL to dd/mm/yyyy really appreciated.
 
You're welcome, glad to help, & thanks for the feedback.:)
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Akuini

Thank you for responding to this query.

I tried using this micro but it doesn't seem to be working for me

Please can you help as I'm having the same issue.

Is it correct to assume that if first 2 number is less than 13 then it must be the false date?
If yes then try this (in small data first):


Code:
Sub flipDate()
Dim va, x
Dim i As Long
va = Range("C2", Cells(Rows.count, "C").End(xlUp))
For i = 1 To UBound(va, 1)
    x = va(i, 1)
    If Left(x, 2) < 13 Then va(i, 1) = DateSerial(Right(x, 4), Left(x, 2), Mid(x, 4, 2))
Next
Range("C2").Resize(UBound(va, 1), 1) = va
End Sub
 
Upvote 0
Hi, AfuaImade
The OP's data problem is like this:
If the first 2 numbers are less than 13 then it means the date is wrong (meaning the days & months have been swapped).

Could you explain your data problem?
Could you explain 'doesn't seem to be working'? Did the code produce a wrong result?
And could you post some data as table?
 
Upvote 0
Hello Akuini,

Thanks for responding. Below is a sample of the data

[TABLE="width: 500"]
<tbody>[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]7851203[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="class: xl65, width: 148, align: right"]12/4/2019 23:14[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]7851569[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="class: xl65, width: 148, align: right"]12/4/2019 23:22[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]1243752[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved by Financial Institution[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]13/04/2019 0:10[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]7852253[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved by Financial Institution[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]13/04/2019 0:30[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]1657054[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="class: xl65, width: 148, align: right"]12/5/2019 23:38[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]7947320[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Kindly enter the OTP sent to 234813***8577[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="class: xl65, width: 148, align: right"]12/5/2019 23:40[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]5347509[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]13/05/2019 0:12[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]5268985[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]13/05/2019 0:49[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]1066630[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]The bank is currently unable to process this transaction. Please try another card or bank account.[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="class: xl65, width: 148, align: right"]12/6/2019 23:21[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]8851513[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 270"]
<tbody>[TR]
[TD="width: 270"]Approved by Financial Institution[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 148"]
<tbody>[TR]
[TD="width: 148"]13/06/2019 0:33[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

The data is specifically for month 4,5,6 (ie April,May,June) so therefore I know that even if the first 2 numbers are less than 13, it doesn't mean that the date as in the first row is not December but April.

When I ran the code, I got the error below highlighted in Yellow

If Left(x, 2) < 13 Then va(i, 1) = DateSerial(Right(x, 4), Left(x, 2), Mid(x, 4, 2))


Hi, AfuaImade
The OP's data problem is like this:
If the first 2 numbers are less than 13 then it means the date is wrong (meaning the days & months have been swapped).

Could you explain your data problem?
Could you explain 'doesn't seem to be working'? Did the code produce a wrong result?
And could you post some data as table?
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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