web 2.0

How to Group by Just Date Portion Of DateTime Field

There are times when we need to group by the table with the date. But Datetime field also contain time part which is very deep. So, there is no way you can group by datetime field and see correct records because it will group by including the time portion of DateTime field.

So, to get rid off the time portion in group by clause here is a quick query.

   1: select  dateadd(dd,0, datediff(dd,0,dateCreated)) as Date,count(*) TotalCount  from tblRecords   
   2: group by dateadd(dd,0, datediff(dd,0,dateCreated)) 

Comments

Deep Patel India, on 8/3/2009 3:31:11 AM Said:

Deep Patel

SQL=" select datevalue(datetimefield) AS date2 ,count(id) as cntid from tablename group by datevalue(datetimefield) order by datevalue(datetimefield) desc"

exercise to enlarge penis United States, on 9/23/2009 1:17:53 AM Said:

exercise to enlarge penis

this sounds ridiculous, i may take a look further to check out the detail
anyway, thanks

panini United States, on 9/28/2009 5:17:08 PM Said:

panini

ahh now i know hot to group tables with the date.

Niche Blueprint 2.0 Review United States, on 12/27/2009 8:29:38 PM Said:

Niche Blueprint 2.0 Review

I love reading your posts. I wish you a Happy New Year!

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading