laravel select dates except weekend code example
Example: get date excluding somedays php
<?php
public static function getOrderEndDate( $start_date, $orderDaysCode ){
$saturday_off = false;
if( $orderDaysCode == 'meal_monthly_6' ) { $orderDays = 24; }
elseif( $orderDaysCode == 'meal_monthly_5' ) {
$orderDays = 20;
$saturday_off = true;
}elseif( $orderDaysCode == 'meal_weekly' ) {
$orderDays = 5;
$saturday_off = true;
}
else{ $orderDays = 1; }
$formatted_date = new DateTime( $start_date );
$date_timestamp = $formatted_date->getTimestamp();
for( $i = 0; $i < ( $orderDays - 1 ); $i++ ) {
$nextDay = date('w', strtotime('+1day', $date_timestamp) );
if( $nextDay == 0 || ( $nextDay == 6 && $saturday_off ) ) { $i--; }
$date_timestamp = strtotime('+1day', $date_timestamp);
}
$formatted_date->setTimestamp($date_timestamp);
return $formatted_date->format( 'Y-m-d' );
}
$orderEndDate = getOrderEndDate( '2020-06-17',
'meal_monthly_6' );
?>