Dear reader,
I've been struggling for months to find a solution to this kind of simple issue. Now I thought clock() was it. Well, it seems, it's not.
goal:
calculate difference of elapsed time (preferably in minutes) between two dates (startdate, datestamp - like "2016-12-14 19:04:35").
method:
result:
id 1-3 with timediff = 0 though there is a difference of some seconds!!!
id 4 scores better (> 0), but not correct, nonetheless (actually < 1 min instead of 02:11 min)!!!
id 5 should score 03:32 min, not just 02:11 min!!!
Some idea, what's wrong?
Thanks a lot for tips on that
Franz
I've been struggling for months to find a solution to this kind of simple issue. Now I thought clock() was it. Well, it seems, it's not.
goal:
calculate difference of elapsed time (preferably in minutes) between two dates (startdate, datestamp - like "2016-12-14 19:04:35").
method:
Code:
clear set obs 5 gen id = _n //create date strings gen str20 startdate = "" gen str20 datestamp = "" //interview start replace startdate = "2016-12-14 19:04:35" if id == 1 replace startdate = "2016-11-08 16:40:04" if id == 2 replace startdate = "2016-11-24 19:47:30" if id == 3 replace startdate = "2016-11-15 14:15:46" if id == 4 replace startdate = "2016-11-25 21:01:22" if id == 5 //interview end replace datestamp = "2016-12-14 19:04:53" if id == 1 replace datestamp = "2016-11-08 16:40:17" if id == 2 replace datestamp = "2016-11-24 19:48:03" if id == 3 replace datestamp = "2016-11-15 14:16:19" if id == 4 replace datestamp = "2016-11-25 21:04:54" if id == 5 //convert to numeric vars gen startnum = clock(startdate, "YMD hms") fre startnum gen endnum = clock(datestamp, "YMD hms") fre endnum //calculate the actually wanted difference gen timediff = endnum - startnum fre timediff format timediff %tc list id timediff
id 1-3 with timediff = 0 though there is a difference of some seconds!!!
id 4 scores better (> 0), but not correct, nonetheless (actually < 1 min instead of 02:11 min)!!!
id 5 should score 03:32 min, not just 02:11 min!!!
Some idea, what's wrong?
Thanks a lot for tips on that
Franz
Comment