Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php check the date is Saturday

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?

like image 782
tonoslfx Avatar asked Mar 14 '11 12:03

tonoslfx


3 Answers

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';
}
like image 162
oezi Avatar answered Sep 30 '22 00:09

oezi


This should do it:

if(date("w",$timestamp)==6)
    echo "Saturday";
like image 42
Gareth Avatar answered Sep 30 '22 01:09

Gareth


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.

like image 42
ChrisH Avatar answered Sep 30 '22 02:09

ChrisH