How do I repeat a fiscal year?

I am new to PHP and I have a question about how to respond to a fiscal year.

For the calendar year echo, I use:

<?php echo date("y"); ?> 

My fiscal year begins on July 1 of the previous calendar year and ends on June 30, and I want to repeat the fiscal year.

I do not know how to do that. I have been looking for answers to this problem, but I cannot find an easy solution for me.

Expected Result

If this happens in June 2015, I want to print 2015 as the year, and then print 2016 , starting on the first day of the next month.

+8
source share
6 answers

try something like:

 if ( date('m') > 6 ) { $year = date('Y') + 1; } else { $year = date('Y'); } 

Short hand designation:

 $year = ( date('m') > 6) ? date('Y') + 1 : date('Y'); 
+13
source

This should be simple enough, something like:

 if (date('m') <= 6) { $year = date('Y'); } else { $year = date('Y') + 1; } 

Alternatively, you can use one expression that maps the month to zero / one value, depending on whether it is in the first or second half of the calendar year, and then adds it to the calendar year:

 $year = date('Y') + (int)((date('m') - 1) / 6); 
+2
source

Try the following:

 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); } 
+2
source

Too easy

 if (date('m') >= 6) { $year = date('Y') + 1; } else { $year = date('Y'); } 

try this one!

+2
source

For India, the fiscal year begins in April of each year.

Mostly FY 2019-20

To do this, use the 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 
0
source

You can simply call:

 echo date('Y', mktime(0, 0, 0, 6+date('m'))); 

According to mktime docs:

The number of the month relative to the end of the previous year. Values ​​1 through 12 indicate the normal calendar months of the year in question. Values ​​less than 1 (including negative values) indicate the months of the previous year in the reverse order, so 0 is December, -1 is November, etc. Values ​​greater than 12 indicate the corresponding month next year.

Appendix 6 for current monthly shifts to the expected fiscal year.

-1
source

All Articles