Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I want to hide Saturday and Sunday in PHP.

I´ve build the following code:



			$begin = new DateTime($row['date']);
$end = new DateTime($row['dateul']);
$end = $end->modify( '+1 day' ); 

$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);

foreach($daterange as $date){
	
 $array[] = $date->format("Y-m-d");

}


Until here the code is working but it outputs the complete week/days in this daterange.

I found this code:

if (strcasecmp($daterange, 'Sun') != 0
         && strcasecmp($daterange, 'Sat') != 0){

     }


Do i understand it right, that if value = 1 it will output Saturday for example?

Because the main idea was the following:
if day for example sunday = 0 hide it in array, if sunday=1 show it in array.
The values are getting from mysql. i hope you can help me. Thanks a lot

What I have tried:

Found some of the above code while using google but dont know how to solve my problem.
Posted
Updated 21-Dec-20 2:49am

The expression is checking that the $daterange value is not 'Sat' or 'Sun. However, each $daterange item is not a simple three letter string representing the day of the week, so that code will not work. You need to check each $date item (which I assume is a DateTime object) in your loop to see what day of the week it represents.
 
Share this answer
 
Your question subjects include MySQL and I assume you get some sort of date-containing data from a SQL query.

Why not build the SQL query so that it only sends back the days of the week you want to begin with? This cleans up your php and does so rather painlessly. Use the DAYOFWEEK() function

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900