I need to get how many January's have occurred between two dates in TSQL.
I.e. If any day in January in a particular year has been included then this counts as 1 per year rather than multiple times per month.
As an example, the following would give the result = 1
declare @date1 datetime = '2018-09-01 00:00:00.000';
declare @date2 datetime = '2019-02-01 00:00:00.000';
As an example, the following would give the result = 1, as there has been 1 day into January
declare @date1 datetime = '2018-09-01 00:00:00.000';
declare @date2 datetime = '2019-01-01 00:00:00.000';
As an example, the following would give the result = 0 as there has been no days in January
declare @date1 datetime = '2018-09-01 00:00:00.000';
declare @date2 datetime = '2018-11-01 00:00:00.000';
As an example, the following would give the result = 2 as there has been two occurrences of January
declare @date1 datetime = '2017-09-01 00:00:00.000';
declare @date2 datetime = '2019-11-01 00:00:00.000';