Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

muragijimana's avatar

Sir How can I add date range to my Api json format

for example this Api URL:https://public-api.wordpress.com/rest/v1/freshly-pressed

How can i Do it Thank you so much.

0 likes
3 replies
theFinalArbiter's avatar

God day respected sir!

How about adding some dates to your request, then validate them something like

$this->validate($request, [
        'start_date' => 'required|date',
        'end_date' => 'required|date'
]);

then you can do things like

$q->where('created_at', '>=', date('Y-m-d').' 00:00:00'));
$cars = Car::selectRaw('DATEDIFF(MIN(start_date), MAX(end_date)) as date_diff')->get();

Not sure if syntax is right or most efficient solution.. problably you should also check end_date > start_date.

Please or to participate in this conversation.