get date excluding somedays php

Solutions on MaxInterview for get date excluding somedays php by the best coders in the world

showing results for - "get date excluding somedays php"
Elliot
09 Jul 2017
1<?php 
2
3   public static function getOrderEndDate( $start_date, $orderDaysCode ){
4        $saturday_off = false;
5        if( $orderDaysCode == 'meal_monthly_6' ) { $orderDays = 24; }
6        elseif( $orderDaysCode == 'meal_monthly_5' ) {
7            $orderDays = 20;
8            $saturday_off = true;
9        }elseif( $orderDaysCode == 'meal_weekly' ) {
10            $orderDays = 5;
11            $saturday_off = true;
12        }
13        else{ $orderDays = 1; }   // Daily Meal
14
15        $formatted_date = new DateTime( $start_date );
16
17        $date_timestamp = $formatted_date->getTimestamp();
18        // loop for X days
19        for( $i = 0; $i < ( $orderDays - 1 ); $i++ ) {
20            // get what day it is next day
21            $nextDay = date('w', strtotime('+1day', $date_timestamp) );
22            // if it's Sunday or Saturday get $i-1
23            if( $nextDay == 0 || ( $nextDay == 6 && $saturday_off ) ) { $i--; }
24            // modify timestamp, add 1 day
25            $date_timestamp = strtotime('+1day', $date_timestamp);
26        }
27
28        $formatted_date->setTimestamp($date_timestamp);
29
30        return $formatted_date->format( 'Y-m-d' );
31    }
32
33	$orderEndDate = getOrderEndDate( '2020-06-17',
34                                    'meal_monthly_6' );
35
36?>