碳 - 按日期比较两个日期

问题描述 投票:0回答:2

最近我试图比较两个日期的日期。例如,我想检查一下学生是否在每个月的5个月内支付了他/她的费用。

更多的例子,学生在2019-01-13注册,现在是2019-03-20所以我想系统通知我学生费用时间超过7天。它也应该自动检查下个月。

php laravel date php-carbon
2个回答
0
投票

您可以定义任务计划

$schedule->command('student:fees_notify')->monthlyOn(5, '01:00');

您可以根据您的逻辑进行schudele命令。它将在月份开始的第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
   }
}

0
投票

它看起来应该是这样的

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;
  }
});

该数组将包含超过其日期的用户

© www.soinside.com 2019 - 2024. All rights reserved.