Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

113
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda