php检查日期是星期六

问题描述:

如何检查日期是星期六。php检查日期是星期六

<input id="datePicker" name="datePicker" type="text" class="textinput date-pick"> 

我的代码:

if(date('Y-m-d', strtotime('this Saturday')) == $_SESSION['search_date']) { 
    echo 'Event this saturday'; 
} else { 
    echo 'Event on the others day'; 
} 

上面的代码只是呼应下周活动!如果我搜索一周后或三周等,没有显示结果?

+0

试日期('N',yourTS) – Teson 2011-03-14 12:49:23

+0

如果日期不是星期六,您想要做什么而不是检查? (或者你的意思是“是否”?:P) – 2011-03-14 12:53:35

在php文档中查看date()。您chould更改您的代码是这样的:

if(date('w', strtotime($_SESSION['search_date'])) == 6) { 
    echo 'Event is on a saturday'; 
} else { 
    echo 'Event on the others day'; 
} 
+0

像冠军一样工作;) – tonoslfx 2011-03-14 12:54:09

这应做到:

if(date("w",$timestamp)==6) 
    echo "Saturday"; 

检查:http://nl2.php.net/manual/en/function.date.php date('w', strtotime($_SESSION['search_date']))应该给平日。检查它是否是6,这是星期六。

日期(“L”)返回一天有问题的文字表述,所以我应该这样做:

$date = strtotime($_SESSION['search_date']); 
if (date('l', $date) == 'Saturday'){ 
// you know the rest 
} 

//Just sharing 

//these lines of codes returns "Holidays: Sat & Sun" based on given start and end date 

date_default_timezone_set('Asia/Kuala Lumpure'); 

$startDate = '2014-01-03'; 

$endDate = '2014-01-23'; 

$st_arr = explode('-', $startDate); 

$en_arr = explode('-', $endDate); 

$st_tot = intval($st_arr[0]+$st_arr[1]+$st_arr[2]); 

$en_tot = intval($en_arr[0]+$en_arr[1]+$en_arr[2]); 

$count = 0; 

for($i = $st_tot ; $i <= $en_tot ; $i++) { 

//Increase each day by count: goes according to the calender val 

    $date = strtotime("+" .$count." day", strtotime($startDate)); 
    $x = date("Y-m-d", $date); 

    if(date("w",strtotime($x))==6 || date("w",strtotime($x))==0) { 
     echo "holiday - ". $x. '<br>'; 
    } else { 
     echo "Nope - ". $x. '<br>'; 
    } 

    $count++; 
}