Transform Date & Time

bdenn

New Member
Joined
Feb 3, 2017
Messages
29
Office Version
  1. 365
Platform
  1. Windows
Hello,
I have a large data set which I filter by hour. Within each hour I could have lots of random times (02:00:12, 02:00:21, 02:00:35, etc.) is it possible to transform all of these date/time entries to display each entry as 02:00:00.

I would like to not add another column if possible.

Thanks,
Bdenn
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Not my code but tested on Column A and works

VBA Code:
Option Explicit 'First line at your module ensures you declare any variables

Public Sub FloorFormat()
    Dim lastRow As Long
    
    With Worksheets("Sheet1") 'Your sheet name here
        lastRow = .Range("A" & .Rows.Count).End(xlUp).Row 'find last used row
        
        Dim i As Long
        For i = 1 To lastRow 'do the following for all used rows in column A
            .Cells(i, "A").Value = Application.WorksheetFunction.Floor(.Cells(i, "A").Value, 1 / 24)
        Next i
    End With
End Sub
 
Upvote 0
Hello,
Is it possible without using VBA?

Thanks,
Bdenn
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    ChangeType = Table.TransformColumnTypes(Source,{{"Time", type time}}),
    tbl = Table.TransformColumns(ChangeType, {{"Time", each #time(Time.Hour(_) ,0,0)}})
in
    tbl

Book4
ABCD
1TimeTime
26:01:58 PM6:00:00 PM
31:16:30 PM1:00:00 PM
410:19:24 PM10:00:00 PM
57:15:31 PM7:00:00 PM
63:51:16 PM3:00:00 PM
72:15:09 AM2:00:00 AM
812:49:32 PM12:00:00 PM
910:08:32 AM10:00:00 AM
1012:08:17 PM12:00:00 PM
1110:35:54 PM10:00:00 PM
129:09:07 AM9:00:00 AM
137:15:37 PM7:00:00 PM
149:12:48 AM9:00:00 AM
155:36:11 AM5:00:00 AM
165:39:01 AM5:00:00 AM
178:53:30 AM8:00:00 AM
184:53:42 PM4:00:00 PM
195:12:22 PM5:00:00 PM
203:47:11 AM3:00:00 AM
2110:45:59 AM10:00:00 AM
2210:47:49 AM10:00:00 AM
234:46:01 AM4:00:00 AM
249:00:48 PM9:00:00 PM
25
Sheet1
 
Upvote 0
Solution

Forum statistics

Threads
1,224,000
Messages
6,175,896
Members
452,681
Latest member
jlcm0924

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