The following SQL shows how to get the current financial year using SQL.
This assumes that the financial year for your country is 1 July – 30 June.
This SQL query uses
- GETDATE to get the current date
- MONTH to turn the date into the month number (e.g. 5)
- YEAR to turn the date into the year number (e.g. 2017)
- CAST to convert the number to a string
SELECT CASE WHEN MONTH( GETDATE() ) <= 6 THEN CAST( YEAR(GETDATE() ) - 1 AS varchar(4) ) + '/' + CAST( YEAR(GETDATE()) AS varchar(4) ) /* 2016/2017 */ ELSE CAST( YEAR(GETDATE() ) AS varchar(4) ) + '/' + CAST( YEAR(GETDATE()) + 1 AS varchar(4) ) /* 2017/2018 */ END AS Current_Financial_Year