Get dates of a given Day in PHP and MySQL

Algorithm


Code Examples

#1 Code Example with PHP Programming

Code - PHP Programming


> get current date
$end_data = '2021-05-01'; // Get from Frontend Input

$dates = [];

while(strtotime($date) < strtotime( $end_data ) ) {
	
	$day_num  = date( 'd', strtotime( $date ) );
	$day_name = date( 'l', strtotime( $date ) );
	$date    = date("Y-m-d", strtotime("+1 day", strtotime($date)));
	
	if ( in_array( $day_name, $days_between_range ) ) {
	    $dates[] = $date;
	}
}
    
print_r($dates);

/************************ 
Expected output: 
*************************
Array
(
    [0] => 2021-04-19
    [1] => 2021-04-20
    [2] => 2021-04-25
    [3] => 2021-04-26
    [4] => 2021-04-27
)
*/
Copy The Code & Try With Live Editor

Output

x
+
cmd
Array
(
[0] => 2021-04-19
[1] => 2021-04-20
[2] => 2021-04-25
[3] => 2021-04-26
[4] => 2021-04-27
)

Demonstration


Get dates of a given Day in PHP and MySQL