[英]Carbon - Comparing two dates by their days
最近,我试图按日期比较两个日期。 例如,我想检查一下学生是否在每个月的5日内支付了学费。
例如,学生在2019-01-13
注册,现在是2019-03-20
因此我想系统地通知我,学生费用时间已过去7天。 以及它应该自动检查下个月。
您可以定义任务计划
$schedule->command('student:fees_notify')->monthlyOn(5, '01:00');
您可以根据自己的逻辑安排命令。 它将在月份开始的第5个日期(01:00)触发
您的命令看起来像
class StudentFeesNotify extends Command
{
protected $signature = 'student:fees_notify';
protected $description = 'your desc.....';
public function handle()
{
// you can write your logic here
}
}
它应该看起来像这样
use Carbon\Carbon // don't forget to import carbon in your class
$days = 5;
// i would recommend to use chunk if you have a lot of records & limit this query t only people that might be subject to this alert
$students= Student::get();
$notifyList = [];
// assuming that the registration date column is created at and it's a valid date
$students->each(function($student) use (&$notifyList,$days){
$notify = Carbon::parse($student->registration_date)->addDays($days)->lt(Carbon::now());
if($notify){
$notifyList[] = $student;
}
});
该数组将包含超过其日期的用户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.