views:

322

answers:

5

I have a query like this:

SELECT COUNT(*) AS amount
FROM daily_individual_tracking
WHERE sales = 'YES'
AND daily_individual_tracking_date BETWEEN '2010-01-01' AND '2010-03-31'

I am selected from a date range. Is there a way to also get the total days in the date range?

A: 

What exactly are you trying to count? The total number of distinct values of daily_individual_tracking_date? Do you need it in the same query as the count(*) query?

brydgesk
+7  A: 

Not really clear if you are looking for

DATEDIFF('2010-03-31', '2010-01-01')

or

COUNT(DISTINCT daily_individual_racking_date)
Unreason
I am looking for DATE DIFF thanks!!!
John Isaacks
A: 

You can use the MySQL datediff function:

SELECT DATEDIFF('2010-01-01','2010-01-31') AS DiffDays

It should return a floating point, where 1.0 represents a single day.

Andomar
A: 

This depends on what SQL server you're using.

If you're using MS-SQL Server, you can use the function DateDiff

Henri
A: 

I'm not sure which SQL you are using. TSQL has a DATEDIFF that will count the nu7mber of days between two dates. See this

MichaelKay