I have an ajax code for grabbing Google Calendar events and I would like to Dynamically place two dates into the URL string that fetched from Google Calendar
The first date (timeMax=2021-02-28)
should grab the current date and add 30 days to it
The second date (timeMin=2021-02-15)
should just gram the current date
My assumption is we would create to date variables one for the first date (timeMax) variable and another for (timeMin) variable. Then place these two variables into the associated URL tag.
Any help in what the code should be would be great. Thank you!
//Jquery's ajax request
$.ajax({
type: 'GET',
url: 'https://www.googleapis.com/calendar/v3/calendars/eaachapter309@gmail.com/events?singleEvents=true&maxResults=30&timeMax=2021-02-28T00:00:00Z&timeMin=2021-02-15T00:00:00Z&orderBy=startTime&key=my_secret_key_goes_here',
dataType: 'json',
async: true
}).done(function(data) {
//once we get a successful response this callback function
//gets fired, and "data" contains the parsed json file .
//here we iterate over the object array
$.each(data.items, function(i, item) {
//I do this to later format these timestamps
//set options for date.toLocaleDateString() function
var options = {
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
};
let start = new Date(item.start.dateTime).toLocaleDateString('en-US', options);
let end = new Date(item.end.dateTime).toLocaleDateString('en-US', options);
let end_splt = end.split(',');
//append data to the list.
if (item.status != "cancelled") {
$('table.isSearch tbody').append(`<tr mbr-list mbr-list-grow="tableColumns"><td class="body-item mbr-fonts-style display-7" width=15%>${item.summary}</td><td class="body-item mbr-fonts-style display-7" width=25%>${start} - ${end_splt[1]}</td><td class="body-item mbr-fonts-style display-7" width=60%>Location: ${item.location}<br><br>${item.description}</td></tr>`);
}
});
}).fail(function(e) {
error(e);
});
var months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>