I have string data on start and end times of an activity in "hhmm" format. I want to find the total time spent on the task. However, I am facing a problem.
Code:
gen seconds= 0 split time_from, p(:) destring time_from1 time_from2, replace rename (time_from1 time_from2)(hour minute) gen from_time = hms(hour,minute,second) format %tcCCYY-NN-DD_hh:MM_AM from_time drop hour minute split time_to, p(:) destring time_to1 time_to2, replace rename (time_to1 time_to2)(hour minute) gen to_time = hms(hour,minute,second) //format %tcCCYY-NN-DD_hh:MM_AM to_time drop hour minute second
Code:
gen time_spent = to_time - from_time
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str5(time_from time_to) "04:00" "08:00" "08:00" "08:30" "08:30" "09:00" "09:00" "10:00" "10:00" "10:30" "10:30" "11:00" "11:00" "11:30" "11:30" "15:00" "15:00" "15:30" "15:30" "18:00" "18:00" "19:00" "19:00" "19:30" "19:30" "20:30" "20:30" "21:00" "21:00" "04:00" "04:00" "07:30" "07:30" "08:00" "08:00" "08:30" "08:30" "10:00" "10:00" "10:30" "10:30" "11:00" "11:00" "15:00" "15:00" "15:30" "15:30" "16:00" "16:00" "18:30" "18:30" "19:00" "19:00" "19:30" "19:30" "21:00" "21:00" "04:00" "04:00" "08:00" "08:00" "08:30" "08:30" "09:00" "09:00" "10:00" "10:00" "10:30" "10:30" "11:00" "11:00" "11:30" "11:30" "16:00" "16:00" "17:00" "17:00" "19:00" "19:00" "19:30" "19:30" "20:00" "20:00" "22:00" "22:00" "04:00" "04:00" "07:00" "07:00" "07:30" "07:30" "08:00" "08:00" "10:00" "10:00" "10:30" "10:30" "11:00" "11:00" "11:30" "11:30" "16:00" "16:00" "16:30" "16:30" "18:30" "18:30" "19:30" "19:30" "20:00" "20:00" "21:30" "21:30" "04:00" "04:00" "07:00" "07:00" "07:30" "07:30" "08:00" "08:00" "09:00" "09:00" "09:30" "09:30" "10:00" "10:00" "12:00" "12:00" "15:00" "15:00" "18:00" "18:00" "20:00" "20:00" "20:30" "20:30" "21:00" "21:00" "04:00" "04:00" "08:00" "08:00" "08:30" "08:30" "09:00" "09:00" "10:00" "10:00" "10:30" "10:30" "11:00" "11:00" "13:00" "13:00" "16:00" "16:00" "18:00" "18:00" "19:30" "19:30" "20:00" "20:00" "21:00" "21:00" "04:00" "04:00" "06:00" "06:00" "06:30" "06:30" "07:00" "07:00" "08:00" "08:00" "09:00" "09:00" "09:30" "09:30" "10:00" "10:00" "12:00" "12:00" "13:00" "13:00" "16:00" "16:00" "18:00" "18:00" "18:30" "18:30" "19:30" "19:30" "20:00" "20:00" "21:00" "21:00" "21:30" "21:30" "04:00" end
0 Response to Calculate difference between two clock times
Post a Comment