cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper II
Helper II

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: How to add hours to DateTime data?

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.

Specializing in Power Query Formula Language (M)

View solution in original post

16 REPLIES 16
Highlighted
Community Champion
Community Champion

Re: How to add hours to DateTime data?

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.

Specializing in Power Query Formula Language (M)

View solution in original post

Highlighted
Helper II
Helper II

Re: How to add hours to DateTime data?

I tried this to type the function #duration function but it's not coming up. Power Bi does not recognize it. Do you know why? 

Highlighted
Regular Visitor

Re: How to add hours to DateTime data?

Same here.. that #Duration formula doesn't works

Highlighted
Community Champion
Community Champion

Re: How to add hours to DateTime data?

#duration is a Power Query (M) function to be used in the Query Editor.

 

And it is case-sensitive, so #Duration won't work in any case.

Specializing in Power Query Formula Language (M)
Highlighted
Regular Visitor

Re: How to add hours to DateTime data?

Sorry, i write Duration here, but i tried with duration as follows:

 

StartDate = (adx_events[adx_releasedate] + #duration(0,10,0,0))

 

i get this error on powerbi query editor:

 

The following syntax error occurred during parsing: Invalid token, Line 1, Offset 32, #.

Highlighted
Community Champion
Community Champion

Re: How to add hours to DateTime data?

In the code below I copied your line without any modification and it works fine.

 

let
    Source = {40000..40001},
    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Changed Type" = Table.TransformColumnTypes(#"Converted to Table",{{"Column1", type date}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "adx_releasedate"}}),
    adx_events = #"Renamed Columns"{0},
    StartDate = (adx_events[adx_releasedate] + #duration(0,10,0,0))
in
    StartDate

 

You can copy/paste this code into your query editor and see for yourself.

Specializing in Power Query Formula Language (M)
Highlighted
New Member

Re: How to add hours to DateTime data?

Hi

 

How do you add 10hrs to all dates in the list instead of just one?

Highlighted
Community Champion
Community Champion

Re: How to add hours to DateTime data?

Please don't hijack other topics for your own question, but start a new topic instead.

 

And don';t forget to react to replies you get, maybe give kudos, mark replies as answer, which you still have to do for your for your first and only topic so far, raised in April 2016.

Specializing in Power Query Formula Language (M)
Highlighted
New Member

Re: How to add hours to DateTime data?

My apologies, i believed my question was still on topic, asking a question about your answer and would enhanse the existing thread

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors