0

How can I show upcoming events which start 2 weeks later than today and finish on 6 weeks later than today. For example if today is 1st of January the events will be shown from 15th of January to 15th of February

This is my function which is shown the events but it will show the whole events.

function listUpcomingEvents() {
        var request = gapi.client.calendar.events.list({
          'calendarId': 'primary',
          'timeMin': (new Date()).toISOString(),
          'showDeleted': false,
          'singleEvents': true,
          'maxResults': 10,
          'orderBy': 'startTime'
        });

        request.execute(function(resp) {
          var events = resp.items;
          appendPre('Upcoming events:');

          if (events.length > 0) {
            for (i = 0; i < events.length; i++) {
              var event = events[i];
              var when = event.start.dateTime;
              if (!when) {
                when = event.start.date;
              }
              appendPre(event.summary + ' (' + when + ')')
            }
          } else {
            appendPre('No upcoming events found.');
          }

        });
      }
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Flap Jack
  • 97
  • 1
  • 14

1 Answers1

0

Use the timeMin and timeMax properties in your list request, providing the dates of interest. See documentation here.

Your script currently has just 'timeMin': (new Date()).toISOString(), which says to list all events that start later than now.

This answer shows how to calculate the dates you'll use for your parameters.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275