Quantcast
Channel: Forum SQL Server Database Engine
Viewing all articles
Browse latest Browse all 15889

How to use this function to calculate Datediff, Datepart etc

$
0
0

Hello Forum

I have created the following function to set the start of the financial year.  What I need to know is how to use this function in order to perform date functions within a database where the start of the financial year is week 1: -

Create FUNCTION [dbo].[FinencialYearStartDate]
(@Date DATETIME) RETURNS VARCHAR(10) AS
BEGIN
DECLARE @RetVal varchar(10)
Declare @Month int
Declare @Year int
case
        when month(getdate()) > 3
            SET @RetVal = (convert(datetime, cast(year(getdate()) as varchar) + '/04/01'))
        else
            SET @RetVal = (convert(datetime, cast(year(getdate()) - 1 as varchar) + '/04/01'))
End
 Return @RetVal
End


Please click "Mark As Answer" if my post helped. Tony C.



Viewing all articles
Browse latest Browse all 15889

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>