Calculating beginning of fiscal year based on current date

I have to calculate the beginning of the current fiscal year, July 1, based on the current date.

For 6/11/2014 the beginning of the Fiscal Year would be '2013-07-01'.

For 8/15/2015 the beginning of the Fiscal Year would be '2015-07-01'.

What is proper syntax to calculate this?

Thanks

Glen
GPSPOWAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chaauCommented:
I think this will do:
convert(date, convert(varchar(4), case when datepart(month, yourdate) < 7 then datepart(year, yourdate)-1 else datepart(year, yourdate) end)+'0701') 

Open in new window

SQL Fiddle
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HuaMin ChenProblem resolverCommented:
Try this way
declare @dt datetime,
	@ret_dt datetime
select @dt=convert(datetime,'20140611',112)

if (substring(convert(varchar,@dt,112),5,4)>'0630')
	select @ret_dt=convert(datetime,substring(convert(varchar,@dt,112),1,4)+'0701',112)
else
	select @ret_dt=convert(datetime,substring(convert(varchar,dateadd(year,-1,@dt),112),1,4)+'0701',112)
print @ret_dt

declare @dt datetime,
	@ret_dt datetime
select @dt=convert(datetime,'20140711',112)

if (substring(convert(varchar,@dt,112),5,4)>'0630')
	select @ret_dt=convert(datetime,substring(convert(varchar,@dt,112),1,4)+'0701',112)
else
	select @ret_dt=convert(datetime,substring(convert(varchar,dateadd(year,-1,@dt),112),1,4)+'0701',112)

Open in new window

to get fiscal starting date
0
HuaMin ChenProblem resolverCommented:
Please run the above separately
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

GPSPOWAuthor Commented:
Thanks

I tried using it in a select statement with various dates and it worked just like I want it.

Glen
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
GPSPOW- I just kicked out an article that deals specifically with Fiscal calendar planning --> SQL Server Calendar Table:  Fiscal Years.   Let me know if this helps you.  If yes, click on the 'Good Article' button and provide some feedback.  Thanks.
1
GPSPOWAuthor Commented:
Excellent article.

I will begin using this in my future programming projects.

Thanks

Glen
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.