Created
April 5, 2017 18:35
-
-
Save kmfolgar/e0f2c9017b5a36501fe12589a9930127 to your computer and use it in GitHub Desktop.
How to substract two times in hours and minutes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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