Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
How to repeat event for every 2 weeks on multi selection days up to 3 Occurrence's

I'm working on a google calendar kind of repeat feature using angularjs/php. enter image description here

Trying repeat the event for every 2 weeks on multi selection of days and that event will be repeated up to 3 occurrence's (times) from start date. PFA my code.

$scope.daysarr = [{dayname: "SUN",Name: 'Sunday', Selected: true},
{dayname: "MON",Name: 'Monday', Selected: false},
{dayname: "TUE",Name: 'Tuesday', Selected: true},
{dayname: "WED",Name: 'Wednesday', Selected: false},
{dayname: "THU",Name: 'Thursday', Selected: true},
{dayname: "FRI",Name: 'Friday', Selected: false},
{dayname: "SAT",Name: 'Saturday', Selected: false}];

for ($i=1; $i<=$after_occurance ; $i++) { // 3times
if($i==1)
{
    $datesArr[] = $date->format('Y-m-d');
}
else
{
    echo $dayOfWeek = $date->format('l');
    if ($dayOfWeek == 'Sunday' && $daysarr[0]->selected==1) { // i want to loop sun,tue,thu
        $date->modify("+{$repeatnum} weeks");   // 2 weeks
            $datesArr[] = $date->format('Y-m-d');
    }
    if ($dayOfWeek == 'Tuesday' && $daysarr[2]->selected==1) { // i want to loop sun,tue,thu
        $date->modify("+{$repeatnum} weeks");   // 2 weeks
            $datesArr[] = $date->format('Y-m-d');
    }
    if ($dayOfWeek == 'Thursday' && $daysarr[4]->selected==1) { // i want to loop sun,tue,thu
        $date->modify("+{$repeatnum} weeks");   // 2 weeks
            $datesArr[] = $date->format('Y-m-d');
    }
            
}}

Getting output only selected start date in repeat instead of selected days

expected output:

sun: 09-jan-2022, 23-jan-2022, 06-feb-2022

tue: 04-jan-2022, 18-jan-2022, 01-feb-2022

thu: 06-jan-2022, 20-jan-2022, 03-feb-2022

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I would do it using seconds based on the provided startDate converted to EPOCH:

<?php
   // convert startDate input to epoch time
   $startDate = strtotime($_POST['startDate']);

   // how many seconds does 2 weeks contain?
   $interval = 2 * 7 * 24 * 60 * 60;

   // calculate and display the startDate, followed by its next ocurrences
   for ($i=0; $i<$after_occurance; $i++) { // 3times
      if ($i == 0) {
         // output the first date with the Day name
         echo date("D, d-m-Y", ($startDate + ($i * $interval)));
      } else {
         // all other dates won't display the day name
         echo date("d-m-Y", ($startDate + ($i * $interval)));
      }
      // if not last, add a comma and a space to the output
      if ($i < $after_occurance-1) { 
          echo ', ';
      } else {
          echo '<br/>';
      }
   }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!