How to get Financial Year from Date IN SQL Server
CREATE FUNCTION [dbo].[FinencialYear]
(@Date DATETIME)
RETURNS VARCHAR(7) AS
BEGIN
DECLARE @RetVal varchar(7)
Declare @Month int
Declare @Year int
Select @Month=Month(@Date)
Select @Year=Year(@Date)
-- Assuming that the financial year is starting from april
if @Month>3
Begin
Set @RetVal=cast(@Year As varchar(10))+'-'+cast(right('0' + rtrim(@Year+1),2) as varchar(2))
End
Else
Begin
Set @RetVal=cast(@Year-1 as varchar(10))+'-'+cast(right('0' + rtrim(@Year),2) as varchar(2));
End
Return @RetVal
End
================================================
select dbo.FinencialYear('02/02/2013')
==================Our Put======================
2012-13
(@Date DATETIME)
RETURNS VARCHAR(7) AS
BEGIN
DECLARE @RetVal varchar(7)
Declare @Month int
Declare @Year int
Select @Month=Month(@Date)
Select @Year=Year(@Date)
-- Assuming that the financial year is starting from april
if @Month>3
Begin
Set @RetVal=cast(@Year As varchar(10))+'-'+cast(right('0' + rtrim(@Year+1),2) as varchar(2))
End
Else
Begin
Set @RetVal=cast(@Year-1 as varchar(10))+'-'+cast(right('0' + rtrim(@Year),2) as varchar(2));
End
Return @RetVal
End
================================================
select dbo.FinencialYear('02/02/2013')
==================Our Put======================
2012-13
Comments
Post a Comment