Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I have a bunch of product orders and I'm trying to group by the date and sum the quantity for that date. How can I group by the month/day/year without taking the time part into consideration?

3/8/2010 7:42:00 should be grouped with 3/8/2010 4:15:00

1 Answer

0 votes
by (119k points)

You can use the following SQL Query to do group by date time column:

SELECT count (CAST (my_DateTime AS DATE))

FROM dbo.table_name


or you can also use CONVERT instead of CAST like following:

SELECT count (CONVERT(CHAR(8),DateTimeColumn,10))

FROM dbo.table_name

GROUP BY CONVERT(CHAR(8),DateTimeColumn,10)

I recommend this SQL Certification course if you wish to learn writing SQL queries and check out this SQL tutorial to learn more about CAST and CONVERT functions.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.2k users

Browse Categories