Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How to calculate Date + time

Hello,

 

I want to calculate a date/time + time to get results in date/time. 

My data setting is following:

 

Column A: Date/time [DD:MM:YYYY hh:nn:ss]

Column B: Time [hh:nn:ss]

 

Results in column C should be 

Column A + Column B= Column C (date/time [DD:MM:YYYY hh:nn:ss])

 

I tried to set up this formula but it doesn't work.

 

Thanks for help,

Petr

  • Hi Anonymous ,

     

    You can use the following measure to convert Decimal number [in hours] to Time value

     

    Measure =
    VAR vSeconds =
        MAX ( 'Table'[Hours] ) * 3600
    VAR vMinutes =
        INT ( vSeconds / 60 )
    VAR vRemainingSeconds =
        MOD ( vSeconds, 60 )
    VAR vHours =
        INT ( vMinutes / 60 )
    VAR vRemainingMinutes =
        MOD ( vMinutes, 60 )
    RETURN
        TIME ( vHours, vRemainingMinutes, vRemainingSeconds )

     

     

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    Best Regards,

    Dedmon Dai

3 Replies

  • Hi Anonymous ,

     

    Is this what you are looking for:

     

    Thanks,

    Pragati

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

       

      I've found the different issue.

      I have the Number of hours in decimal number, which I transfer to time format. But if decimal nubmer is higher than 24, the time is then incorrect.

      So I need to calculate following vallues:

       

      Column A: Date/Time [dd:mm:yy hh:mm:ss]

      Column B: Decimal number [in hours]

       

      I need to calculate columna A + B to get result in Date/Time.

       

      Thanks

      Petr

      • v-deddai1-msft's avatar
        v-deddai1-msft
        Icon for Community Support rankCommunity Support

        Hi Anonymous ,

         

        You can use the following measure to convert Decimal number [in hours] to Time value

         

        Measure =
        VAR vSeconds =
            MAX ( 'Table'[Hours] ) * 3600
        VAR vMinutes =
            INT ( vSeconds / 60 )
        VAR vRemainingSeconds =
            MOD ( vSeconds, 60 )
        VAR vHours =
            INT ( vMinutes / 60 )
        VAR vRemainingMinutes =
            MOD ( vMinutes, 60 )
        RETURN
            TIME ( vHours, vRemainingMinutes, vRemainingSeconds )

         

         

         

        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

         

        Best Regards,

        Dedmon Dai