Reputation: 3413
I have trouble with Carbon's between function. It is giving me a false although I am expecting a true. Here is my code
$now=Carbon::now();
$updated_at=$checkup->updated_at;
if($updated_at->between($now->subMonths($program->months_since_checkup),$now))
//$program->months_since_checkup returns the number 12.
Any thoughts?
P.S. let me add that updated_at is March 23,2016 and is pulled as a carbon object too.
Upvotes: 3
Views: 15511
Reputation: 579
When you type this
$now->subMonths($program->months_since_checkup)
It will subtract 12 months of your variable $now
modifying it.
To solve this try to separate these two variables:
$first = Carbon::now();
$second = Carbon::now()->subMonths($program->months_since_checkup);
if ($updated_at->between($first, $second)) {
Upvotes: 11