Formatting date/times issue

jamiek

New Member
Joined
Dec 14, 2013
Messages
15
Office Version
  1. 365
Hi,

I am trying to sort orders by date/time within the CSV export from my order system, however when I try to sort it does the dates correctly, but not the times (hour/minute).

How can I make it so the sort works for the hour/minute as well? I tried changing the formatting to see if that would help but for some reason no matter what formatting I select, the formatting doesn't actually change the text displayed in the cells.

Please see image below.

Link to CSV file on Google Drive here link to CSV

Would love some help :confused:

Thanks
 

Attachments

  • Screenshot 2021-11-16 at 18.54.09.png
    Screenshot 2021-11-16 at 18.54.09.png
    103.2 KB · Views: 41

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
The data isn't recognized as a date/time. It's just text to excel.

You might highlight all of the data in question, go to the "Data" tab, select "Text to Columns" and then finish.
 
Upvote 0
It looks like the fields are formatted as Text, and not as valid Date/Time fields, so it will not sort the way that you want (it will follow alphabetic sorting rules, not numeric ones).
If you do a "Text to Columns" on column A, choosing the Date option with the "MDY" format, and clicking Finish, it should then convert all those values to valid date/time values that you can sort.
If you want to change the display format of the field after doing that, you can do that in order to get it to look the way you want.
 
Upvote 0
The data isn't recognized as a date/time. It's just text to excel.

You might highlight all of the data in question, go to the "Data" tab, select "Text to Columns" and then finish.

It looks like the fields are formatted as Text, and not as valid Date/Time fields, so it will not sort the way that you want (it will follow alphabetic sorting rules, not numeric ones).
If you do a "Text to Columns" on column A, choosing the Date option with the "MDY" format, and clicking Finish, it should then convert all those values to valid date/time values that you can sort.
If you want to change the display format of the field after doing that, you can do that in order to get it to look the way you want.

Thanks both.

I just tried this and it formats the first 3 rows of dates but not the others, even though they are selected.

What could be preventing Excel from formatting the rest of the dates?
 
Upvote 0
Regional date setting, perhaps.
If you are not using American-standard dates (MDY) and your default settings are (DMY), it thinks the first part is a day, and not a month, and the second part is a month, and not a day, which is problematic when you get to values over 12.

Are you using a European version of Excel, or do you know what your default date settings are?
 
Upvote 0
Regional date setting, perhaps.
If you are not using American-standard dates (MDY) and your default settings are (DMY), it thinks the first part is a day, and not a month, and the second part is a month, and not a day, which is problematic when you get to values over 12.

Are you using a European version of Excel, or do you know what your default date settings are?
Yes, I am in the UK so my standard is (DMY) but my order system export uses (MDY).

Do I need to change something in the preferences of Excel then?
 
Upvote 0
Hmmm... This is hard for me to test, because I am in the United States, so cannot really replicate your situation easily.
You could change your Windows Regional Setting, but I don't know if you really want to do that.

Another option is to use formulas to convert the entries in to valid dates.
 
Upvote 0
1. Insert 2 columns B and C.
2. Select the range such as A2:A6 and use Data Text To Columns with Delimiter " " space
Date specify MDY
Do not import columns Skip for Time and for PM
Put the data into B2
3. Enter the formula into C2 and fill down
4. Convert C2:C6 to values
5. Delete columns B and C
6. Format to your preference


USA dates to International.xlsm
ABC
1
212/27/2020 11:09:04 PM27-Dec-2027-Dec-2020 23:09
32/4/2020 11:09:04 PM4-Feb-2004-Feb-2020 23:09
411/12/2021 11:09:04 PM12-Nov-2112-Nov-2021 23:09
511/12/2021 4:09:04 AM12-Nov-2112-Nov-2021 04:09
64/27/2021 6:00:00 PM27-Apr-2127-Apr-2021 18:00
7
1e
Cell Formulas
RangeFormula
C2:C6C2=B2+MID(A2,FIND(" ",A2)+1,11)
 
Upvote 0
Instead of inserting columns, you can put the date from Text to Columns after the data. See below.
If you prefer, convert column D to values and then copy to column A
Then delete columns C and D.
Could your order system export in another format say yyyymmdd hh:mm:ss?

USA dates to International.xlsm
ABCD
1Date - Order DateOrder - NumberDate Date and Time
211/12/2021 12:22:29 AM224772433012-11-2112-Nov-21 00:22:29
311/12/2021 4:28:50 PM224801515012-11-2112-Nov-21 16:28:50
411/12/2021 9:40:50 PM224692243312-11-2112-Nov-21 21:40:50
511/13/2021 10:18:13 PM225011996213-11-2113-Nov-21 22:18:13
611/13/2021 3:16:01 PM224778067513-11-2113-Nov-21 15:16:01
711/13/2021 5:41:50 AM224902463813-11-2113-Nov-21 05:41:50
811/13/2021 8:03:40 PM224819564913-11-2113-Nov-21 20:03:40
911/13/2021 8:20:05 PM224991663413-11-2113-Nov-21 20:20:05
1011/13/2021 9:42:52 PM225005857413-11-2113-Nov-21 21:42:52
1111/14/2021 4:54:16 AM225062004214-11-2114-Nov-21 04:54:16
1211/14/2021 8:16:09 PM224974543714-11-2114-Nov-21 20:16:09
1311/14/2021 8:55:09 PM225167371814-11-2114-Nov-21 20:55:09
1411/15/2021 1:41:04 PM225282617015-11-2115-Nov-21 13:41:04
1511/15/2021 10:53:41 PM225371755415-11-2115-Nov-21 22:53:41
1611/15/2021 10:57:14 AM225061673915-11-2115-Nov-21 10:57:14
1711/15/2021 11:04:15 PM225152619515-11-2115-Nov-21 23:04:15
1811/15/2021 11:09:36 AM225062249115-11-2115-Nov-21 11:09:36
19
1d
Cell Formulas
RangeFormula
D2:D18D2=C2+MID(A2,FIND(" ",A2)+1,11)
 
Last edited:
Upvote 0
A VBA solution see the results below.
select the relevant range such as A2:A18
run the macro It converts the text to Values and Formats with the system defaults
The sub also custom formatted the date and time
VBA Code:
Sub FixDatesMDY()
  
  With Selection
    .TextToColumns DataType:=xlDelimited, Tab:=False, Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 5)
    .NumberFormat = "dd-mmm-yyyy hh:mm:ss"
  End With
End Sub

USA dates to International.xlsm
AB
1Date - Order DateOrder - Number
212-Nov-2021 00:22:292247724330
312-Nov-2021 16:28:502248015150
412-Nov-2021 21:40:502246922433
513-Nov-2021 05:41:502249024638
613-Nov-2021 15:16:012247780675
713-Nov-2021 20:03:402248195649
813-Nov-2021 20:20:052249916634
913-Nov-2021 21:42:522250058574
1013-Nov-2021 22:18:132250119962
1114-Nov-2021 04:54:162250620042
1214-Nov-2021 20:16:092249745437
1314-Nov-2021 20:55:092251673718
1415-Nov-2021 10:57:142250616739
1515-Nov-2021 11:09:362250622491
1615-Nov-2021 13:41:042252826170
1715-Nov-2021 22:53:412253717554
1815-Nov-2021 23:04:152251526195
19
3a
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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