...">

Check php date saturday

how to check if the date is saturday.

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

my code is:

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

Above code is repeated only for next week's event! if I search for a week or 3 weeks, etc., the result is not displayed?

+6
php if-statement
source share
5 answers

take a look at date () in the php documentation. you can 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'; } 
+11
source share

This should do it:

 if(date("w",$timestamp)==6) echo "Saturday"; 
+4
source share

Note: http://nl2.php.net/manual/en/function.date.php date('w', strtotime($_SESSION['search_date'])) should indicate the day of the week. Make sure he's 6, Saturday.

+1
source share

date ('l') returns the textual representation of the day in question, so I would do the following:

 $date = strtotime($_SESSION['search_date']); if (date('l', $date) == 'Saturday'){ // you know the rest } 
0
source share
 //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("Ymd", $date); if(date("w",strtotime($x))==6 || date("w",strtotime($x))==0 ) { echo "holiday - ". $x. '<br>'; } else { echo "Nope - ". $x. '<br>'; } $count++; } 
0
source share

All Articles