Forum Discussion
Anonymous
9 years agoNot applicable
How to add hours to DateTime data?
I have a column DateTimeCreated (Example: 2016-12-20 19:40) and I want to add 10 hours to this resulting in 2016-12-21 05:40. Is this possible?
- 9 years ago
You can add a duration to a datetime field, e.g. if your fieldname is "DateTime":
[DateTime] + #duration(0,10,0,0))
The arguments of#duration are days, hours, minutes, seconds.
TimoRiikonen
Advocate V
6 years agoThis accepted solution works for integers, but not for decimals.
If you wish to support decimals as well, then you should convert the value to second and round it.
This one add four hours in M / PowerQuery to column createdon:
#"Added Hours" = Table.ReplaceValue(#"Previous line",each [createdon], each DateTime.From([createdon]) + #duration(0,0,0,Number.Round(4 * 3600)), Replacer.ReplaceValue,{"createdon"})
Anonymous
5 years agoNot applicable
TimoRiikonen This helped but still I felt it was difficult to convert.
For thos who need to add hours for example 9.5 hours which is (34,200 seconds) then use the forumla as below,
[Last Refreshed Date and Time] + #duration(0,0,0,34200)
In other words all your decimal values convert to seconds easily add.
Thanks,
Karthik