Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accurate way of calculating number of minutes between two date-time variables

    Hi Stata users,

    I am trying to calculate the difference in two time variables. Specifically the number of minutes. However, the values are extremely high thus making me doubtful of my approach

    Below is example of data and code


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(starttime endtime)
    1964773055000 1964774205000
    1964184062000 1964184781000
    1965543394000 1965544096000
    1965543324000 1965544493000
    1964778662000 1964779912000
    1966582789000 1966583607000
    1965335964000 1965336457000
    1965557824000 1965559059000
    1964725268000 1964726312000
    1963784182000 1963785019000
    1964453202000 1964454149000
    1964773427000 1964774837000
    1964756345000 1964758603000
    1964855490000 1964858866000
    1963816784000 1963835307000
    1964460386000 1964462217000
    1964464432000 1964465760000
    1964109593000 1964111118000
    1964598809000 1964600240000
    1964772166000 1964773127000
    1964861746000 1964863132000
    1964773886000 1964787498000
    1963829303000 1963831469000
    1964692478000 1964693120000
    1965889781000 1965890819000
    1965458523000 1965459115000
    1966130325000 1966131237000
    1965544191000 1965545046000
    1965542372000 1965544393000
    1964698360000 1964699728000
    1964801957000 1964806641000
    1964781910000 1964782839000
    1964778763000 1964783959000
    1965545166000 1965547141000
    1964771025000 1964771739000
    1964851324000 1964854151000
    1964748658000 1964749733000
    1964454477000 1964457218000
    1965575320000 1965578449000
    1964773240000 1964774149000
    1964700976000 1964704565000
    1964264594000 1964266288000
    1964919682000 1964920385000
    1965489337000 1965490029000
    1964760132000 1964773001000
    1964378774000 1964385824000
    1964772199000 1964778215000
    1964452337000 1964453277000
    1964349537000 1964352894000
    1966077314000 1966078819000
    end
    format %tc starttime
    format %tc endtime
    Code:
    gen duration = (endtime - starttime) / 60
    Is there something am missing?

    Thanks in advance!

  • #2
    Time differences are in milliseconds.

    Code:
    gen duration = (endtime - starttime) / (60*1000)

    Comment


    • #3
      Andrew Musau thanks so much for your advice. It's highly appreciated.

      Comment

      Working...
      X