计算小时分数

时间:2019-11-11 11:36:19

标签: stata

我在字符串变量中存储了一些日期和时间,如下所示:

18apr1985 05:47:23
25may1986 11:34:29
08jan1987 18:00:12
11aug1988 20:56:34
30sep1989 22:19:08

如何找到小时分数?

1 个答案:

答案 0 :(得分:0)

以下对我有用:

clear

input str19 datetime
"18apr1985 05:47:23"
"25may1986 11:34:29"
"08jan1987 18:00:12"
"11aug1988 20:56:34"
"30sep1989 22:19:08"
end

generate double datetime2 = clock(datetime, "DMYhms")
generate wanted = (mm(datetime2) / 60) + (ss(datetime2) / 3600)

list

     +-------------------------------------------+
     |           datetime   datetime2     wanted |
     |-------------------------------------------|
  1. | 18apr1985 05:47:23   7.983e+11   .7897222 |
  2. | 25may1986 11:34:29   8.330e+11   .5747222 |
  3. | 08jan1987 18:00:12   8.527e+11   .0033333 |
  4. | 11aug1988 20:56:34   9.030e+11   .9427778 |
  5. | 30sep1989 22:19:08   9.388e+11   .3188889 |
     +-------------------------------------------+