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
Advertisement
Answer
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.