Created
October 21, 2019 15:58
-
-
Save connect-dips/90bbcfd4cea02a37ce8b5c8e0e65d7d5 to your computer and use it in GitHub Desktop.
A javascript method using momentjs to get determine the current financial year.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let fy = getFinancialYear(); | |
$('#displayFy').text('Financial year is: ' + fy); | |
$( "input#datePicker" ).change(function() { | |
fy = getFinancialYear($(this).val()); | |
$('#displayFy').text('Financial year is: ' + fy); | |
}); | |
function getFinancialYear(date) { | |
let financialYear; | |
let today = moment(); | |
if(date){ | |
today = moment(date, 'YYYY-MM-DD'); | |
} | |
if(today.month() >= 3){ | |
financialYear = today.format('YYYY') + '-' + today.add(1, 'years').format('YYYY') | |
} | |
else{ | |
financialYear = today.subtract(1, 'years').format('YYYY') + '-' + today.add(1, 'years').format('YYYY') | |
} | |
return financialYear | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment