# PHP end a financial year in june of every year

118

I would like to do something of this sort in php, when the month reaches June 2016, I would like to echo 2016-17, but before that i echo 2015-16 What I have so far echos 2015-16 meaning it changes with the beginning of the year, but i would rather it does that in june onwards,

``````echo   date('Y') .'-'.date('y', strtotime('+1 year'));
``````

Any suggestions

548

#### Solution:

Very basic but you can use it:

``````<?php
if (date('m') > 6) {
\$year = date('Y')."-".(date('Y') +1);
}
else {
\$year = (date('Y')-1)."-".date('Y');
}
echo \$year; // 2015-2016
?>
``````

Explanation:

If current month is greater than 6 than it will print current year and +1 Year and hyphen (-) between them.

If current month less than 6 than it will print current year and -1 Year and hyphen (-) between them.

637

#### Solution:

This can be solved with a simple oneliner:

``````echo date('n') > 6 ? date('Y').'-'.(date('Y') + 1) : (date('Y') - 1).'-'.date('Y');
``````

The "n" format character is better in this case, as it returns the month without leading zero.

Be aware, that this solution depends on your machine's timezone settings. If you use this in an international, or at least in many timezones, this might be incorrect.

109

#### Solution:

Try this :

``````if(date('m') >= 06) {
\$d = date('Y-m-d', strtotime('+1 years'));
echo   date('Y') .'-'.date('y', strtotime(\$d));
} else {
\$d = date('Y-m-d', strtotime('-1 years'));
echo   date('Y', strtotime(\$d)).'-'.date('y');
}
``````

People are also looking for solutions to the problem: php - Null result while use and operator in MYSQL IN

Source