need tsql code for time intervel and the values should go to that particular interval the original time is in epoch format -


i have add column table. column value calculated based on column present in table.

i have time-stamp (column present) , group them 5 min time-slots.

e.g: if time is:

  • 13:03/13:02 should go 13:00;
  • 13:53/13:52 should go 13:50;
  • 13:21 should go 13:20 , on

ps: have time stamp in epoch (unix time stamp)format [the table has values in epoch in regular time stamp]

so i'm seeing have times , need round them down nearest 5 minute increment. try this:

declare @table table (times time)  insert @table values  ('13:03'),         ('13:02'),         ('13:53'),         ('13:52'),         ('13:21');  select  times,         dateadd(minute,-datediff(minute,0,times) % 5,times) five_minute_increments @table 

results:

times              five_minute_increments ----------------   ---------------------- 13:03:00.0000000   13:00:00.0000000 13:02:00.0000000   13:00:00.0000000 13:53:00.0000000   13:50:00.0000000 13:52:00.0000000   13:50:00.0000000 13:21:00.0000000   13:20:00.0000000 

epoch version

declare @epoch bigint;  --epoch seconds since jan 1,1970 set @epoch = datediff(second,'1970-01-01','2015-04-01 12:06:00.000');  select cast(dateadd(second,@epoch - (@epoch %300),'1970-01-01 00:00:00.000') time) epochtimes 

results:

12:05:00.0000000 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -