Hello i want to compare dates in laravel
please tell me this code is right.
I want to check it before login.
- When user is registered, user must be deactivated
- Admin must activate the user: end_date=activated_date +90 days
- Admin Deactivation : end_date=deactivated_date;
- if current_date=deactivate_date
if ($user->activated_at ->gte(now()->subDays(90)))
{
return $this->sendError('messages.user_subscription', [], 400);
}
2
Answers
You can check whether
$first
is before or after$second
using:or vice versa:
And if you need to get calculate difference, you can use below commands for difference in seconds and hours:
Yes you code is correct, if it does not work you have to add activated_at in $dates in User model