title: How do I format datetime data to fit google calendar api's date field?
body: <p>Goal: create a Google Calendar event.</p>
  
  <p>Blocker: the date formatting.</p>
  
  <hr>
  
  <p>background: I'm trying to create a meal planner that takes recipes from a given database and creates events with their name in a google calendar. The database looks like this:</p>
  
  <pre><code>d = {'recipe_id': ['carrot salad', 'leek fritters'], 'meal_date': ['2020-05-28 22:28:01.204464+00:00', '2020-05-29 22:28:01.204464+00:00']}    
  df = pd.DataFrame(data=d)
  </code></pre>
  
  <p>the meal date is a product of two</p>
  
  <pre><code>today_date = datetime.datetime.utcnow().isoformat() + 'Z'
  df['menu_date'] = today_date
  df['menu_date'] = pd.to_datetime(df['menu_date'])
  df['meal_date'] = df['menu_date'] + df['meal'].apply(pd.offsets.Day)
  </code></pre>
  
  <p>Where 'meal' is just a number (1, 2, etc) and the last command just shifts today's date by that amount.</p>
  
  <p>When I use the following code to upload to google calendar I get an error:</p>
  
  <pre><code>def myconverter(o):
      '''
      call the __str__ method of the datetime object that will return a string representation of the value
      ___
  
      shoutout: https://code-maven.com/serialize-datetime-object-as-json-in-python
      '''
      if isinstance(o, datetime.datetime):
          return o.__str__()
  
  def add_to_calendar(df, calendar_id):
      """Shows basic usage of the Google Calendar API.
      Prints the start and name of the next 10 events on the user's calendar.
      """
      creds = None
      # The file token.pickle stores the user's access and refresh tokens, and is
      # created automatically when the authorization flow completes for the first
      # time.
      if os.path.exists('token.pickle'):
          with open('token.pickle', 'rb') as token:
              creds = pickle.load(token)
      # If there are no (valid) credentials available, let the user log in.
      if not creds or not creds.valid:
          if creds and creds.expired and creds.refresh_token:
              creds.refresh(Request())
          else:
              flow = InstalledAppFlow.from_client_secrets_file(
                  'credentials.json', SCOPES)
              creds = flow.run_local_server(port=0)
          # Save the credentials for the next run
          with open('token.pickle', 'wb') as token:
              pickle.dump(creds, token)
  
      service = build('calendar', 'v3', credentials=creds)
  
      # Call the Calendar API
      now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
      print('Adding meals to calendar')
  
      for i, r in df.iterrows():
          event = {
          'summary': r.name,
          'description': r.meal_period,
          'start': {
              'date': json.dumps(r.meal_date, default=myconverter),
              'timeZone': 'America/Los_Angeles'
          },
          'end': {
              'date': json.dumps(r.meal_date, default=myconverter),
              'timeZone': 'America/Los_Angeles'
          }
          }
          event = service.events().insert(calendarId=calendar_id, body=event).execute()
  </code></pre>
  
  <p>running this code, I get the following error:</p>
  
  <pre><code>HttpError: &lt;HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID/events?alt=json returned "Invalid value for: Invalid format: ""2020-05-28 22:28:01.204464+00:00"""&gt;
  </code></pre>
  
  <p>where CALENDAR_ID is my google calendar id.</p>
  
  <p>If anyone knows how to fix this date issue using python code, this would be incredibly helpful.</p>