Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Create DateTime List between start datetime & end DateTime

Hello

 

I hope someone can help?

 

I want to create a list of datetimes between a Start DateTime column and an End DateTime column in Power Query with  1 hour between . I have tried this but it didn't work using add Custom Column

 = List.DateTimes([#"Shift Start Time"], [#"Shift End Time"], #duration(0,1,0,0))

 

Example

 

Table currently looks like this

Start DateTime                             End DateTime     

01/01/2020 00:00:00                     01/01/2020 04:00:00

 

i want it to look like this 

 

Start DateTime                             End DateTime                               Custom

01/01/2020 00:00:00                     01/01/2020 04:00:00                    01/01/2020 00:00:00 

01/01/2020 00:00:00                     01/01/2020 04:00:00                    01/01/2020 01:00:00 

01/01/2020 00:00:00                     01/01/2020 04:00:00                    01/01/2020 02:00:00 

01/01/2020 00:00:00                     01/01/2020 04:00:00                    01/01/2020 03:00:00 

01/01/2020 00:00:00                     01/01/2020 04:00:00                    01/01/2020 04:00:00 

 

I have nearly no experience with M so it I would be grateful if I could get a statement to use to create a custom column

 

Thanks

Joe 

  • Anonymous 

     

    You may use code below to add a custom column.

    List.DateTimes([Start DateTime], Duration.Hours([End DateTime] - [Start DateTime]) + 1, #duration(0,1,0,0))

     

2 Replies

  • v-chuncz-msft's avatar
    v-chuncz-msft
    Community Support

    Anonymous 

     

    You may use code below to add a custom column.

    List.DateTimes([Start DateTime], Duration.Hours([End DateTime] - [Start DateTime]) + 1, #duration(0,1,0,0))

     

    • yyyyyyyy's avatar
      yyyyyyyy
      New Member

      Can you fix this so that it always end with the End Date and Time and the hours inbetweena are rounded to the end of the hour?