Skip to content

Instantly share code, notes, and snippets.

@kmfolgar
Created April 5, 2017 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kmfolgar/e0f2c9017b5a36501fe12589a9930127 to your computer and use it in GitHub Desktop.
Save kmfolgar/e0f2c9017b5a36501fe12589a9930127 to your computer and use it in GitHub Desktop.
How to substract two times in hours and minutes
g endtime=string(end_time)
replace endtime="0"+ endtime if length(endtime)==3
g endh=substr(endtime, 1,2)
g endm=substr(endtime, 3,4)
g starttime=string(start_time)
replace starttime="0"+ starttime if length(starttime)==3
g stah=substr(starttime, 1,2)
g stam=substr(starttime, 3,4)
destring endh endm stah stam, replace
g temph=(endh-stah)*60
g tempm=endm-stam
egen total_time=rowtotal(temph tempm)
drop temph tempm stah stam endh endm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment