How to add events that repeat weekly during specific time in PHP

javascript

#1

I want to make specific time based event in php,

Just like every day 9:00 to 12:00 during Monday-Saturday, except Sunday.

And During 1st To 7Th of Feb.

As like this Image,

For that i have tried something like this,

$start = new DateTime( '2013-10-01' );
$end = new DateTime( '2014-01-01 23:59:59' );
$interval = new DateInterval('P5D');

$period = new DatePeriod($start, $interval, $end);

// only trigger every three weeks...
$weekInterval = 1;

// initialize fake week
$fakeWeek = 0;
$currentWeek = $start->format('W');
var_dump($period);
foreach ($period as $date) {

    if ($date->format('W') !== $currentWeek) {
        $currentWeek = $date->format('W');
        $fakeWeek++;
        print ' WEEK ' . $currentWeek . '<br/>';
    }

    if ($fakeWeek % $weekInterval !== 0) {
        continue;
    }

    $dayOfWeek = $date->format('l');
    if ($dayOfWeek == 'Monday' || $dayOfWeek == 'Wednesday' || $dayOfWeek == 'Friday') {
        print $date->format('Y-m-d H:i:s') . '   ' . $dayOfWeek . '<br/>';
    }
}

Here the issue is that, i want to have Time duration, Just like 9 O'clock every day during specific time frame and for specific days, So how can i specify that in DatePeriod?


#2

You would specify that on the start date.


#3

For selection of hours,
Like Every day 12 O'clock, All Week Except Sunday, During 1st-7th Feb.

Issue is with daily time selection and repeat


#4

You have determined the start date


#5

I already have the start and end dates, but between those dates for specific time frame it has to repeat, look at image i put


closed #6

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.