for sql server 2012+
deduct 6 months from the given date, take the year of that and add 2 years, convert that year with month 7 day 1
DECLARE @OrigDate date = '20140630' -- NB! safest YYYYMMDD format
select
datefromparts(year(dateadd(year,2,dateadd(month,-6,@OrigDate))),7,1)
;
DECLARE @OrigDate date = '20140702' -- NB! safest YYYYMMDD format
select
datefromparts(year(dateadd(year,2,dateadd(month,-6,@OrigDate))),7,1)
;
see: http://sqlfiddle.com/#!6/d41d8/20720
Continuing on, in earlier sql server versions, we can still deduct 6 months from "the date" and add 2 years but it gets a little more complex as we now need to use more dateadd() calculations. The zero date in sql server is 1900-01-01, so if you add 6 months to it you get 1900-07-01. Then add the required number of years to reach 2015 or 2016 etc to 1900-07-01 you get to July 1 of the required year.
select
the_date
, datefromparts(year(dateadd(year,2,dateadd(month,-6,the_date))),7,1) AS by_dateparts
, dateadd(year,year(dateadd(year,2,dateadd(month,-6,the_date)))-1900,dateadd(month,6,0)) AS by_dateadds
from table1
;
Here are some tests (based on a small table in lieu of using an @ parameter)
| THE_DATE | BY_DATEPARTS | BY_DATEADDS |
|------------|--------------|-----------------------------|
| 2014-06-24 | 2015-07-01 | July, 01 2015 00:00:00+0000 |
| 2014-06-30 | 2015-07-01 | July, 01 2015 00:00:00+0000 |
| 2014-07-06 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-07-12 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-07-18 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-07-24 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-07-30 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-08-05 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-08-11 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2014-08-17 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2015-06-24 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2015-06-30 | 2016-07-01 | July, 01 2016 00:00:00+0000 |
| 2015-07-06 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
| 2015-07-12 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
| 2015-07-18 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
| 2015-07-24 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
| 2015-07-30 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
| 2015-08-05 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
| 2015-08-11 | 2017-07-01 | July, 01 2017 00:00:00+0000 |
http://sqlfiddle.com/#!6/2d5f4/4
by the way. YYYYMMDD is the safest date format of all in sql server. MM/DD/YYYY is not safe, so while I would like to see you avoid string manipulation when doing date calculations, if you are doing it that way use YYYYMMDD