Forum Discussion
Hours between timestamps
- 3 years ago
Solved this through a few steps:
#"Added Custom" = Table.AddColumn(#"Inserted Time1", "Custom", each [SHIFTENDDATETIME]-[SHIFTSTARTDATETIME]),
#"Inserted Hours" = Table.AddColumn(#"Added Custom", "Hours", each Duration.Hours([Custom]), Int64.Type),
#"Inserted Minutes" = Table.AddColumn(#"Inserted Hours", "Minutes", each Duration.Minutes([Custom]), Int64.Type),
#"Added Custom1" = Table.AddColumn(#"Inserted Minutes", "Hours (30 min lunch)", each ([Hours]+([Minutes]/60))-.5),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom", "Hours", "Minutes"}) - 3 years ago
Ah yes, correct! Then use the Duration.TotalSeconds: https://learn.microsoft.com/en-us/powerquery-m/duration-totalseconds
It will be easier to use I think.
Hello CarlBlunck , I think that what you need is one of the Duration functions. See documentation here: https://learn.microsoft.com/en-us/powerquery-m/duration-seconds
Your function could look like:
hours = Duration.Seconds(dateTime1-dateTime2) / 3600
Hope this helps.
Alexandre
Thanks _AlexandreRM_ unfortuately all of the duration functions just extract the portion of the duration out. So duration.seconds will just give you the seconds of the calculated duration. Which in my case, returns 0.
- _AlexandreRM_3 years agoHelper II
Ah yes, correct! Then use the Duration.TotalSeconds: https://learn.microsoft.com/en-us/powerquery-m/duration-totalseconds
It will be easier to use I think.
- CarlBlunck3 years agoResolver I
Ha it pays to scroll down and read the rest of the available functions list. Thank mate, much cleaner. Went with the Duration.TotalHours function as still gives decimals.