Announcement

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

  • Convert milliseconds to days and hours for elapsed time

    Hi,

    I am trying to format elapsed times as HH:MM. However, some time length are over 24 hours and HH has a limit 0-24. Below is an example of my data:

    arrival departure time elapsed
    28feb2019 19:57:00 12mar2019 16:16:00 1023540000

    I want "time elapsed" to be shown as "284:19" in my data. Is there a way to do so?

    Thank you in advance,
    Cole

  • #2
    Code:
    set obs 1
    gen double arrival= tc(28feb2019 19:57:00)
    gen double departure= tc(12mar2019 16:16:00)
    format arrival departure %tc
    gen hours= int((departure- arrival)/(1000*60*60))
    gen minutes= ((departure- arrival)/(1000*60*60) - hours)*60
    gen wanted= string(hours)+":"+ string(minutes)
    Res.:

    Code:
    . l
    
         +--------------------------------------------------------------------+
         |            arrival            departure   hours   minutes   wanted |
         |--------------------------------------------------------------------|
      1. | 28feb2019 19:57:00   12mar2019 16:16:00     284        19   284:19 |
         +--------------------------------------------------------------------+

    Comment


    • #3
      Thank you very much, Andrew!

      Comment

      Working...
      X