1

I am working on chronic care health project in which i have to set future dates for patient injection. The doctor select start date for injection and then he select 3 days (i.e. Monday, Wednesday, Friday etc) which means patient will come 3 times a week.

The total injection are 20 that are divided by 3 times a week. The problem that i am facing is that the parse function gives incorrect result if doctor select a day that matches today. Lets suppose today is Wednesday and date is 2019-02-06 and doctor select 3 days that are:

  • Friday
  • Monday
  • Wednesday

Output should be: - 2019-02-08 - 2019-02-11 - 2019-02-13

My code for controller:

   if( $visitstart_date != null)
                   $startDate = Carbon::parse($visitstart_date);  
              else $startDate = Carbon::now(); 

             if($perweek_visit1_day != '')
             {  //Get date of selected day
                $perweek_visit1_dayDate = $startDate->parse($perweek_visit1_day);

            }
             if($perweek_visit2_day != '')
             {  //Get date of selected day
                $perweek_visit2_dayDate = $startDate->parse($perweek_visit2_day);

              }
             if($perweek_visit3_day != '')
             {  //Get date of selected day
                $perweek_visit3_dayDate = $startDate->parse($perweek_visit3_day);
             }

But when dump the 3 values it provide me :

  • 2019-02-08
  • 2019-02-11
  • 2019-02-06 (incorrect)

For testing purpose I also parse the next visit date with each other like:

if( $visitstart_date != null)
                   $startDate = Carbon::parse($visitstart_date);  
              else $startDate = Carbon::now(); 

             if($perweek_visit1_day != '')
             {  //Get date of selected day
                $perweek_visit1_dayDate = $startDate->parse($perweek_visit1_day);

            }
             if($perweek_visit2_day != '')
             {  //Get date of selected day
                $perweek_visit2_dayDate = $perweek_visit1_dayDate ->parse($perweek_visit2_day);

              }
             if($perweek_visit3_day != '')
             {  //Get date of selected day
                $perweek_visit3_dayDate = $perweek_visit2_dayDate ->parse($perweek_visit3_day);
             }

but it again provided me the same output as : - 2019-02-08 - 2019-02-11 - 2019-02-06

I don't know where i am going wrong, any support or help in this regard will be highly appreciated. Thanks,

Amir Khan
  • 183
  • 2
  • 16

0 Answers0