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



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');
foreach ($period as $date) {

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

    if ($fakeWeek % $weekInterval !== 0) {

    $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?


You would specify that on the start date.


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


You have determined the start date


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.