Page 1 of 1

how to use the datepart function to calculate the count at specific time?

Posted: Tue Nov 22, 2016 7:43 pm
by atul.pdm@gmail.com
I need to calculate the count of slots for each hour like 2016-01-01 00:00:00,2016-01-01 01:00:00,..........

I tried using below query but it did not worked,please suggest

Code: Select all

SELECT count(slots) FROM acctn 
WHERE  (DATEPART(mm, start_time) = 00 AND (DATEPART(ss, start_time) = 00

output should be like:

Date   					count
 2016-01-01 00:00:00			value
 2016-01-01 01:00:00			value


Re: how to use the datepart function to calculate the count at specific time?

Posted: Tue Nov 22, 2016 9:50 pm
by JimKnicely
This is one way:

Code: Select all

select count(slots) as slots_cnt,
       to_char(start_time, 'DD-MON-YYYY HH24') as date_hr
  from acctn
 group by 2
 order by 2;