Please Help With Sorting by text: 7 days 6 hours 42 minutes 57 seconds

miva0601

New Member
Joined
Mar 31, 2015
Messages
33
Hello,

I'm creating a pivot table and would like to sort by the below text under Column Time In Queue.

What I've been able to do so far is convert the days, hours, minutes, seconds into a "d.h:mm:ss" format but it looks messy and I'm not sure it's correct.


Time In QueueInvoice AmountVendor ID
22 days 6 hours 45 minutes 51 seconds$20.26326553
21 days 21 hours 3 minutes 38 seconds$244.124142
21 days 20 hours 30 minutes 55 seconds$3,271.259373
16 days 2 hours 44 minutes 9 seconds$2,108.49340233
14 days 11 hours 22 minutes 6 seconds$90.00342924
14 days 9 hours 20 minutes 28 seconds$86.48331774
13 days 17 hours 59 minutes 5 seconds$10,590.0129130
13 days 17 hours 58 minutes 15 seconds$10,451.0829130
8 days 20 hours 20 minutes 26 seconds$1,221.966156
8 days 20 hours 18 minutes 10 seconds$249.976156

<tbody>
</tbody>
Time in Queue
Count of Days

<tbody>
</tbody>
Hour

<tbody>
</tbody>
MinuteSecondTime Value
Time Value Result

<tbody>
</tbody>
d.h:mm:ss
d.h:mm:ss Result

<tbody>
</tbody>
22 days 6 hours 45 minutes 51 seconds2264551'=TIME(E2,F2,G2)
6:45:51

<tbody>
</tbody>
=D2&"."&TEXT([@[Time Value]],"h:mm:ss")

<tbody>
</tbody>
22.6:45:51

<tbody>
</tbody>

<tbody>
</tbody>
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Assuming all your data will always have the format in your OP, here's a UDF (User-Defined Function) you can use like a worksheet function after you install it. Use it as in the example below and you can then sort on Time (Days) column.
Excel Workbook
ABCD
1Time In QueueInvoice AmountVendor IDTime (Days)
222 days 6 hours 45 minutes 51 seconds$20.2632655322.2818403
321 days 21 hours 3 minutes 38 seconds$244.12414221.8775231
421 days 20 hours 30 minutes 55 seconds$3,271.25937321.8548032
516 days 2 hours 44 minutes 9 seconds$2,108.4934023316.1139931
614 days 11 hours 22 minutes 6 seconds$90.0034292414.4736806
714 days 9 hours 20 minutes 28 seconds$86.4833177414.389213
813 days 17 hours 59 minutes 5 seconds$10,590.012913013.7493634
913 days 17 hours 58 minutes 15 seconds$10,451.082913013.7487847
108 days 20 hours 20 minutes 26 seconds$1,221.9661568.84752315
118 days 20 hours 18 minutes 10 seconds$249.9761568.84594907
Sheet1



To install the UDF:
1. With your workbook active press Alt and F11 keys. This will open the VBE window.
2. In the project tree on the left of the VBE window, find your project and click on it.
3. On the VBE menu: Insert>Module
4. Copy the UDF from your browser window and paste it into the white space in the VBE window.
5. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
6. Use the UDF as you would any native Excel function.
7. Make sure you have enabled macros whenever you open the file or the code will not run.
Code:
Function DurationInDays(S As String) As Double
Dim V As Variant, i As Long, Days As Long, Hours As Double, Minutes As Double, Seconds As Double
V = Split(S, " ")
Days = V(0)
Hours = V(2) / 24
Minutes = V(4) / 60 / 24
Seconds = V(6) / 60 / 60 / 24
DurationInDays = Days + Hours + Minutes + Seconds
End Function
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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