M
M
marrs2016-05-18 10:55:15
Working with date/time
marrs, 2016-05-18 10:55:15

Time intervals from 8 to 18 every day OOP?

We set the current day at 8:00 am and output + 6 days.
Every day starts at 8:00 and ends at 18:00

$begin = new DateTime("now");
$begin->setTime(08, 00, 00);

$end = new DateTime("now");
$end->setTime(18, 00, 00);
$end = $end->modify("+6 day 1 second"); 

$interval = new DateInterval('PT1H');
$daterange = new DatePeriod($begin, $interval ,$end);

foreach($daterange as $date){
    if( strtotime($date->format("H:i:s")) >= strtotime("08:00:00") &&
    strtotime($date->format("H:i:s")) <= strtotime("18:00:00") ) {

    	echo $date->format("Y-m-d H:i:s") . "<br>";
  }
}

It works but how to implement without condition
if( strtotime($date->format("H:i:s")) >= strtotime("08:00:00") &&
    strtotime($date->format("H:i:s")) <= strtotime("18:00:00") )

I suppose in DateInterval it is possible to set this parameter?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Shvedov, 2015-07-24
@mmmaaak

Errors in the console look like links for a reason. Have you tried following it?

A
Alexander Zolotykh, 2015-07-24
@zolotykh

Some problem with the $posts provider.
Notice if you have a global variable posts?

O
Oleg Yakovenko, 2015-07-24
@Apx

Well, it seems to be swearing at $posts that there is no provider for this name in $injector.
Option 1. You do not have any service or other with this name in Angular at the time of transition to this state.
Option 2: You are using ui-router. If you use resolve in state configs, then it may simply be that this (or its parent) state does not have such a variable that you are trying to get using DI.

$stpr.state('someState', {
                url: '/someUrl',
                ....
                resolve: {
                   $posts : //достаём посты. $http или ещё как-то
                }
            })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question