2016-09-30 88 views
-1

好吧,我有一個窘境。我有一個應用程序,需要將2016年10月1日上午12點按鈕上顯示的2017-2018年更新。它必須在明年10月1日之前一直保持到明年,並將再次更新至2018-2019年。我如何在PHP中寫這個?每年在特定日期將顯示年份更改爲下一年

+0

你能顯示當前按鈕的代碼?這至少會讓人們有所收穫。 –

回答

0

你可以嘗試像

//the year from is the current year 
$yearFrom = date("Y"); 

//if it's october or later, make the year from NEXT year 
if (date("n")>=10) $yearFrom++; 

//the year to is always the year after the year from 
$yearTo = $yearFrom + 1; 

那麼你的按鈕內

echo $yearFrom."-".$yearTo; 
+0

這是什麼是在當前代碼: '

<?php echo date(「Y」); ?> - <?php echo date(「Y」,strtotime(「+ 1 year」)); ?>

相關問題