I am trying to fetch the closest record of if date not matched in database. But somehow it is not working or you can say giving me the wrong information.
Below is my code that you can check and help me to find the bug.
$atg = @DB::table('mc_atginfo')
->where('SiteId', Input::get('siteId'))
->where('TankId', Input::get('tankId'))
->orderByRaw('ABS(TIMESTAMPDIFF(SECOND, ATGDateTime,?))', [$inputDateTimeFormatted])
->orderBy('ATGDateTime', 'desc')
->first();
return Response::json($atg);
}
Any solution appreciated!
What are you trying to get? please be more descriptive, as it is not clear what you want to get.
If all that you want is the closest record to a date column you have in the table, you would just do: