Jump to content

PHP MSSQL COUNT per Year


Call-911

Recommended Posts

Hello All,

 

I need to count the number of SQL date entries we have per year. I can coun this by:

 

SELECT COUNT(*) FROM news WHERE show='true' AND date >= '2011-07-01'

 

But how can I make it change years automatically. Our fiscal year starts July 1, and I'd like it to restart the count automatically every year. Does that make sense?

Link to comment
https://forums.phpfreaks.com/topic/242588-php-mssql-count-per-year/
Share on other sites

For the year start/end -

SELECT COUNT(*) FROM news WHERE `show`='true' AND IF(CURDATE() >= CONCAT(YEAR(CURDATE()),'-07-01'),
date BETWEEN CONCAT(YEAR(CURDATE()),'-07-01') AND CONCAT(YEAR(CURDATE())+1,'-06-30'),
date BETWEEN CONCAT(YEAR(CURDATE())-1,'-07-01') AND CONCAT(YEAR(CURDATE()),'-06-30'))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.