I am using the fetch API to retrieve some JSON data from a server.
The fetch call looks something like this and relies on the current date in the query string to return the current date's data.
fetch(`https://www.some-url/apps/bookings/calendar-json.php?todayDate=${year}-${month}-${day}`)
.then(r => r.json)... ``
The data returned is essentially showing the available bookings for the current date as set in the API url.
I want to have a set of controls that allows the user to increment or decrement the date by 1 day to show the bookings for that particular date by fetching the new data. To do this I was going to get the current date in ISO format (like below) then split up the year, month, day in to separate variables and use those in the API query string. -
const date = new Date();
const isoFormat = date.toISOString();
const currentDate = isoFormat.substr(0,10);
From there, is it then possible to manipulate the date variables via increment/decrement to get previous or next days dates in the API URL? I suppose a bit like a counter.
Or is there a better way that already exists for handling this? A package like moment.js or something?