Hello,
I have 2 variables for start and end time in numerical form and 2 dummy variables for am/pm and I am trying to calculate the duration. I created 2 string variables from start and end time. However it is in 12-hour format. So, when I simple take the difference, it is not correct.
My goal is to create a viable of the duration between start and end time.
Any help would be appreciated. Here is my code.
*add zero at the beginning
gen str starttimeS = string(starttime)
gen str starttime2 = string(real(starttimeS), "%04.0f")
gen str endtimeS = string(endtime)
gen str endtime2 = string(real(endtimeS), "%04.0f")
*convert str to time format
gen s = clock(starttime2, "hm")
format s %tcHH:MM
gen e = clock(endtime2, "hm")
format e %tcHH:MM
I have 2 variables for start and end time in numerical form and 2 dummy variables for am/pm and I am trying to calculate the duration. I created 2 string variables from start and end time. However it is in 12-hour format. So, when I simple take the difference, it is not correct.
My goal is to create a viable of the duration between start and end time.
Any help would be appreciated. Here is my code.
*add zero at the beginning
gen str starttimeS = string(starttime)
gen str starttime2 = string(real(starttimeS), "%04.0f")
gen str endtimeS = string(endtime)
gen str endtime2 = string(real(endtimeS), "%04.0f")
*convert str to time format
gen s = clock(starttime2, "hm")
format s %tcHH:MM
gen e = clock(endtime2, "hm")
format e %tcHH:MM
Comment