Reputation: 3442
how to check if the date is saturday.
<input id="datePicker" name="datePicker" type="text" class="textinput date-pick">
my code:
if(date('Y-m-d', strtotime('this Saturday')) == $_SESSION['search_date']) {
echo 'Event this saturday';
} else {
echo 'Event on the others day';
}
above code echoing only for the next week event! if i search for week after or 3 week etc, is not showing the result?
Upvotes: 7
Views: 25364
Reputation: 1
//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++;
}
Upvotes: 0
Reputation: 7693
date('l') returns a textual representation of the day in question, so I'd do this:
$date = strtotime($_SESSION['search_date']);
if (date('l', $date) == 'Saturday'){
// you know the rest
}
Upvotes: 0
Reputation: 51797
take a look at date() in the php-documentation. you chould change your code to something like this:
if(date('w', strtotime($_SESSION['search_date'])) == 6) {
echo 'Event is on a saturday';
} else {
echo 'Event on the others day';
}
Upvotes: 13
Reputation: 1281
Check: http://nl2.php.net/manual/en/function.date.php
date('w', strtotime($_SESSION['search_date']))
should give the weekday. Check if it's 6, wich is saturday.
Upvotes: 1