
Untitled
By: a guest on
May 5th, 2012 | syntax:
None | size: 1.13 KB | hits: 11 | expires: Never
Formatting to Timestamps to Interval
ID CAT1 CAT2 realtime V1
21 23 51 11/2/3138 18:29 135
21 23 51 11/2/3138 18:58 132
21 23 51 11/2/3138 21:05 129
21 23 51 11/2/3138 21:05 130
21 23 51 11/2/3138 22:53 142
71 23 52 11/4/3138 6:47 66
71 23 52 11/4/3138 8:45 69
71 23 52 11/4/3138 8:45 68
ID || CAT1 || CAT2 || Interval 0 || Interval 1 || Interval 2 || Interval 3 || ...
21 || 21 || 23 || 135 || 132 || 130 || 142 || ...
71 || 23 || 52 || 66 || 69 || 68 || NULL || ...
d$interval = floor(as.numeric(strptime(d$realtime,"%m/%d/%Y %H:%M"))/1800)
d$interval = paste("Interval", d$interval - min(d$interval))
reshape(d[,names(d) != 'realtime'],idvar=c("ID","CAT1","CAT2"),timevar="interval",direction="wide")
SELECT to_timestamp('11/2/3138 18:29', 'MM/DD/YYYY hh24:mi')
3138-11-02 18:29:00+01
SELECT date_trunc('hour', now())
+ CASE WHEN extract(minute from now()) > 29 THEN 30
ELSE 0 END * interval '1 min'