Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Count by Time Frame

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2012-02-15 : 14:23:15
Hello,

I have a table Posts with a column Created of type Date.

How can I count Posts by date range and period?

For example:

1 - Count, by MINUTE, the POSTS created from 10 of February to 12 of February;

2 - Count, by DAY, the POSTS created from 01 of February to 15 of February;

Thank You,

Miguel

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2012-02-15 : 14:31:19
[CODE]select DateAdd(Minute, DateDiff(Minute, 0, CreatedDate), 0) Minutes, count(*) PostsPerMinute
from Posts
where '20120210' <= CreatedDate and CreatedDate < '20120213'
group by DateAdd(Minute, DateDiff(Minute, 0, CreatedDate), 0)[/CODE]

=================================================
Men shout to avoid listening to one another. -Miguel de Unamuno
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-15 : 14:55:24
see this too

http://visakhm.blogspot.com/2010/01/some-quick-tips-for-date-formating.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -