2016-12-25 86 views
-1

我有一些鏈接,我想包括今年,以及第二年。如何在鏈接中編寫當前和未來的年份?

例如:

<a href="https://www.fakesite.com/search.aspx?&amp;StartDate=12/10/2016&amp;EndDate=12/25/2017">2016 to 2017</a> 

不用手動不得不保持聯繫,我想提出本年度及未來年度動態打印。

任何人都可以告訴我完成此操作的最佳方法嗎?該頁面是PHP,所以我不確定PHP或jQuery是否有簡單的方法,或其他。

我已經試過<?php echo date("Y"); ?>,它沒有在前端工作(這是空白的地方,我試圖讓2016年顯示)。

+0

'echo date(「Y」);'絕對應該工作! – Jeff

回答

0

你可能需要類似:

<?php 
$year = date("Y"); 
$nextYear = $year + 1; 
echo <<< LOL 
<a href="https://www.fakesite.com/search.aspx?StartDate=12/10/$year&EndDate=12/25/$nextYear">$year to $nextYear</a> 
LOL; 
?> 
1

對於這一年

<?php 
$current= new \DateTime(); 
$future = new \DateTime('+ 1 years'); 
?> 

,或者你可以用一條線

$current = (new DateTime)->format("Y"); 

使用它。

<a href="https://www.fakesite.com/search.aspx?&amp;StartDate=<?php echo $current->format('m/d/Y'); ?>&amp;EndDate=<?php echo $future->format('m/d/Y'); ?>"><?php echo $current->format('Y')." to ".$future ->format('Y');?></a> 
相關問題