Forum Discussion

Nandor's avatar
Nandor
Helper I
9 years ago
Solved

Generate a date key

Hi,

 

I have a classical Date&Time column in my database.

I would need to add a new column generated from year, month and day.

 

For example: 20160905 for the 5th of september 2016.

 

Thank you,

Nandor

  • Nandor -

     

    Try this: DateInt = ([Year]*10000)+([Month Nbr]*100)+[DayOfMonth])

  • Hi,

     

    Some very valid suggestions, my personal choice would be to have the following calcualted column:

    =FORMAT ( [YourDateField], "YYYYMMDD" )

     

    Cheers

5 Replies

  • In Power Query/M you could use:

     

    Date.ToText([DateColumn], "yyyMMdd")

    • Nandor's avatar
      Nandor
      Helper I

      Thank you!

       

      All three solutions work perfectly.

       

      Best regards,

      N

  • Hi,

     

    Some very valid suggestions, my personal choice would be to have the following calcualted column:

    =FORMAT ( [YourDateField], "YYYYMMDD" )

     

    Cheers

  • tjd's avatar
    tjd
    Impactful Individual

    Nandor -

     

    Try this: DateInt = ([Year]*10000)+([Month Nbr]*100)+[DayOfMonth])

  • All excellent solutions!

    1. Date.ToText([DateColumn], "yyyMMdd")

    2. DateInt = ([Year]*10000)+([Month Nbr]*100)+[DayOfMonth])
    3. =FORMAT ( [YourDateField], "YYYYMMDD" )

     

    thanks everyone!