2016-12-30 87 views
-5

我希望在我的網站上顯示像問候。如何知道今天是31日12月

只有月份和日期是31 月或1 ST

if($today =='12-31' || $today =='01-01'){  
    echo 'Greetings.';  
} 
+1

你看過php'date()'函數嗎? –

+0

我知道,但如何將比較幫助請 – noob

+0

日期顯示像2016-12-30我只想要月和日期 – noob

回答

0

就產生$今天格式你正在尋找起來以後,使用PHP的date$today = date('m-d');產生在示例代碼中顯示的數字{月} - {天}

<?php 

$today = date('m-d'); 

if($today =='12-31' || $today =='01-01'){ 
    echo 'Greetings.'; 
} 

echo $today; 
0
$yearend_date = strtotime('31 Dec'); 
$yearEnd = date('Y-m-d', $yearend_date); 
$YearStart = date('Y-m-d',strtotime('+1 day',$yearend_date)); 
$today = date('Y-m-d'); 

if($yearEnd==$today || $YearStart==$today){ 
echo "greetings"; 
} 
相關問題