This my code.
/*******************************PHP CODE*****************************************/
if(isset($_GET['date'])){ //
$date = $_GET['date'];
$date = date('Y', strtotime($date));
}
else{
$tomorrow = mktime(0, 0, 0, date("m"), date("d"), date("Y"));
$date = date("Y", $tomorrow);
}
/*************************************************************************/
<table width="214" height="78" border"0">
<tr align="center">
<td colspan="10"><a href="?date=<?= date("Y", strtotime($date .'-1 year')) ?>" title="Previous Day" >Previous Year</a></td>
<td width="95" colspan="2"><a href="?date=<?= date("Y", strtotime($date . '+1 year')) ?>" title="Next Day" >Next Year</a></td>
</tr>
<tr align="center">
<td colspan="12" align="center"></td></tr>
</table>
/***********************************************************/
It is working but if I press NEXT year it will take me to 2013 and then I press
‘PREVIOUS Year’ it take me to 2011 instead of 2012.
You’re getting too crazy with these date functions when all you’re working with is year numbers.
This is identical to simply:
And
$tomorrowdoesn’t make sense there, you’re just getting the current date in a long winded way. You also have some confusing stuff here:And this:
Is the same as simply
$date + 1.Also if you use strtotime, make sure not to mash things together.
strtotime($date .'-1 year')comes out as something likestrtotime('2012-1 year')which will not work, put a space before the minus symbol if you must use this approach.I think this might be what you’re after if you’re just working with years: