HeavenCore | IT Solutions Built on Open Source Software
View Thread
 Print Thread
Get Start of Financial Year for any given date
admin
Simple function to get the start date of the financial year of any given date:


CREATE FUNCTION [dbo].[fn_GetStartOfFinancialYear] ( @DateStr VARCHAR(10) )
RETURNS DATETIME
AS
    BEGIN
      DECLARE @Date DATETIME
      SET @Date = CONVERT(DATETIME, @DateStr, 103)
        RETURN CONVERT(DATETIME, '01/04/' + CONVERT(VARCHAR(4), YEAR(DATEADD(mm,9,@Date)) - 1), 103)
    END
GO


Example Usage:


SELECT  dbo.fn_GetStartOfFinancialYear('06/09/2011') ;
SELECT  dbo.fn_GetStartOfFinancialYear('01/02/2011') ;

Jordon Pilling | Heavencore Administrator
 
Jump to Forum