I need to get 3 types of records in order to send reminders to those ones, first I need to send reminders after 24 hours that the records were created, then after 48 hours and finally after 72 hours.
I have done this so far but it doesn't seem to work properly because, assume that a record was created at 2019-06-10 19:00:00
when the current day turns to 2019-07-10 00:01:00
it seems to consider as if 24 hours have already passed:
$fecha_hoy = Carbon::now();
$solicitudes_24 = SolicitudUser::whereDate(DB::raw('DATE_ADD(created_at, INTERVAL 24 HOUR)'), '<', $fecha_hoy)
->whereDate(DB::raw('DATE_ADD(created_at, INTERVAL 48 HOUR)'), '>', $fecha_hoy)
->whereNull('recordatorio_estado')
->whereHas('curso', function($query){
$query->whereHas('operativo', function ($q){
$q->whereDate('dateOfertaAcademicaOperativoFechaRegistroFin', '>', Carbon::now());
});
})
->where(function($query){
$query->where('registro_completo', 0)
->orWhereNull('registro_completo');
})
->get();
$solicitudes_48 = SolicitudUser::whereDate(DB::raw('DATE_ADD(tblusersSolicitudes.created_at, INTERVAL 48 HOUR)'), '<', $fecha_hoy)
->whereDate(DB::raw('DATE_ADD(tblusersSolicitudes.created_at, INTERVAL 72 HOUR)'), '>', $fecha_hoy)
->where(function($query){
$query->where('recordatorio_estado', 1)
->orWhereNull('recordatorio_estado');
})
->whereHas('curso', function($query){
$query->whereHas('operativo', function ($q){
$q->whereDate('dateOfertaAcademicaOperativoFechaRegistroFin', '>', Carbon::now());
});
})
->where(function($query){
$query->where('registro_completo', 0)
->orWhereNull('registro_completo');
})
->get();
$solicitudes_72 = SolicitudUser::whereDate(DB::raw('DATE_ADD(tblusersSolicitudes.created_at, INTERVAL 72 HOUR)'), '<', $fecha_hoy)
->where(function($query){
$query->where('recordatorio_estado', 2)
->orWhereNull('recordatorio_estado');
})
->whereHas('curso', function($query){
$query->whereHas('operativo', function ($q){
$q->whereDate('dateOfertaAcademicaOperativoFechaRegistroFin', '>', Carbon::now());
});
})
->where(function($query){
$query->where('registro_completo', 0)
->orWhereNull('registro_completo');
})
->get();
How can I solve this?
PD. You can ignore the rest of the query chain that doesn't involve the dates.