cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
shanka Regular Visitor
Regular Visitor

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
MarcelBeug Super Contributor
Super Contributor

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

15 REPLIES 15
MarcelBeug Super Contributor
Super Contributor

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

kaka Regular Visitor
Regular Visitor

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? 

rtrenado Frequent Visitor
Frequent Visitor

Re: How to add hours to DateTime data?

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

MarcelBeug Super Contributor
Super Contributor

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)
rtrenado Frequent Visitor
Frequent 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, #.

MarcelBeug Super Contributor
Super Contributor

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)
quinncallan Frequent Visitor
Frequent Visitor

Re: How to add hours to DateTime data?

Hi

 

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

MarcelBeug Super Contributor
Super Contributor

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)
quinncallan Frequent Visitor
Frequent Visitor

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
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 198 members 2,298 guests
Please welcome our newest community members: