Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
if i select date from 2014-03-14 to 2014-04-06...then i want days count of perticular months
Posted
Comments
Er. Puneet Goel 8-Apr-14 6:05am    
you want to get diff in days or what?
Member 10512629 8-Apr-14 6:33am    
i want days counts between 14 march to 30 march and 1 april to 6 april as saporate when i give input '2014-03-14' AND '2014-04-06'

Do you mean:
SQL
SELECT COUNT(*) FROM MyTable WHERE insertDate BETWEEN '2014-03-14' AND '2014-04-06'

If not, please try to explain in more detail - perhaps with an example?
 
Share this answer
 
Comments
Maciej Los 8-Apr-14 6:20am    
Maybe you're right, +5!
Please, see my answer.
Member 10512629 8-Apr-14 6:27am    
i want days counts between 14 march to 30 march and 1 april to 6 april as saporate when i give input '2014-03-14' AND '2014-04-06'
SQL
SELECT DATEDIFF(dd,'2014-03-14', '2014-04-06') AS CountOfDaysBetweenDates

More: DATEDIFF[^]

[EDIT]
SQL
SELECT CONVERT(VARCHAR(7),entry_date,121) AS PeriodOfTime, COUNT(*) as footfall, sum(amount)/(SELECT DATEPART(dd, DATEADD(dd, DATEPART(dd, DATEADD(mm, 1, max(GE.Active_Date))) * -1, DATEADD(mm, 1,max(GE.Active_Date))))) Avgamount
FROM guest_tbl
WHERE entry_date between '2014-03-14' AND '2014-04-06'
GROUP BY CONVERT(VARCHAR(7),entry_date,121)

[/EDIT]
 
Share this answer
 
v2
Comments
Member 10512629 8-Apr-14 6:27am    
i want days counts between 14 march to 30 march and 1 april to 6 april as saporate when i give input '2014-03-14' AND '2014-04-06'
Maciej Los 8-Apr-14 7:26am    
And... The rule is the same. All you need to do is to find last day of march and first day of april. Have you tried anything?
Member 10512629 8-Apr-14 7:32am    
i have 1 sql query "select count(*) as footfall,sum(amount)/(SELECT DATEPART(dd, DATEADD(dd, DATEPART(dd, DATEADD(mm, 1, max(GE.Active_Date))) * -1, DATEADD(mm, 1,max(GE.Active_Date))))) Avgamount from guest_tbl where entry_date between '2014-03-14' AND '2014-04-06'" ..this is my query...m geting wrong avgamount as it taking 30 day
Member 10512629 8-Apr-14 8:15am    
so i want o/p for march and april...as seporate
Maciej Los 8-Apr-14 8:29am    
See updated answer ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900