php - using Carbon to know if a time falls under two points of time or not -
i using laravel. have come across carbon
there in vendors folder. did quick search , found great extension php date time.
somewhere in application, needed logic check if given time falls between 2 points of time. lets say, want check if 10:00 falls under time time 9:55 , 10:05. surely, falls how should use logic of carbon.
by default carbon::now()
return date , time in 2014-12-02 14:37:18
format. thinking if extract time part i.e 14:37:18
can compare 2 times know whether time under testing falls under 2 points of time or not.
if directly check 2 carbon objects, try check year well. need time part only.
and matter of fact, not sure if times (h:m:s) can directly can compared or not through carbon.
yes there way in carbon, take on documentation here.
to determine if current instance between 2 other instances can use aptly named between() method. third parameter indicates if equal comparison should done. default true determines if between or equal boundaries.
$first = carbon::create(2012, 9, 5, 1); $second = carbon::create(2012, 9, 5, 5); var_dump(carbon::create(2012, 9, 5, 3)->between($first, $second)); // bool(true) var_dump(carbon::create(2012, 9, 5, 5)->between($first, $second)); // bool(true) var_dump(carbon::create(2012, 9, 5, 5)->between($first, $second, false)); // bool(false)
Comments
Post a Comment