How do I echo the financial year?
Solution 1
try something like:
if ( date('m') > 6 ) {
$year = date('Y') + 1;
}
else {
$year = date('Y');
}
Short hand notation:
$year = ( date('m') > 6) ? date('Y') + 1 : date('Y');
Solution 2
Try this:
if (date('m') <= 6) {//Upto June 2014-2015
$financial_year = (date('Y')-1) . '-' . date('Y');
} else {//After June 2015-2016
$financial_year = date('Y') . '-' . (date('Y') + 1);
}
Solution 3
Its too Simple
if (date('m') >= 6) {
$year = date('Y') + 1;
} else {
$year = date('Y');
}
try this one!
Solution 4
That should be simple enough, something like:
if (date('m') <= 6) {
$year = date('Y');
} else {
$year = date('Y') + 1;
}
Alternatively, you could use an single expression that maps the month to a zero/one value depending on whether it's in the first or second half of the calendar year, then adds that to your calendar year:
$year = date('Y') + (int)((date('m') - 1) / 6);
Solution 5
For India,financial year start from April of every Year.
Mostly in FY 2019-20 format
For that use following code:
//for current date month used *** date('m')
$date=date_create("2019-10-19");
echo "<br> Month: ".date_format($date,"m");
if (date_format($date,"m") >= 4) {//On or After April (FY is current year - next year)
$financial_year = (date_format($date,"Y")) . '-' . (date_format($date,"y")+1);
} else {//On or Before March (FY is previous year - current year)
$financial_year = (date_format($date,"Y")-1) . '-' . date_format($date,"y");
}
echo "<br> FY ".$financial_year;
// O/P : FY 2019-20
sunny
I am a PHP developer. I am new in PHP and try to learn PHP.
Updated on July 16, 2022Comments
-
sunny almost 2 years
I am new to PHP and I have a question on how to echo a financial year.
For echo of calendar year, I use:
<?php echo date("y"); ?>
My financial year starts on 1 July of the previous calendar year and concludes on 30 June, and I want to echo the financial year.
I have no any idea how I can do it. I searched for answers to this problem but I cannot find an easy solution for me.
Expected output
If it is sometime in June 2015, I want to print
2015
as the year, and it would then print2016
starting on the first day of the following month. -
Danny Beckett about 5 yearsI don't think this is right. If my financial year starts in April (not July like the OP) then I'd swap
6
for3
. Assuming we're currently in January 2019 then$m = 1
butecho date('Y', mktime(0, 0, 0, 3+$m));
outputs2019
when it should output2018
until the end of March 2019. ideone.com/f010Lx