code: def datetime_to_iso(date, only_date=True):
      
      if only_date:
          return date.isoformat().split('T')[0]
      return date.isoformat()
docs: Convert datetime format to ISO 8601 time format
  
      This function converts a date in datetime instance, e.g. ``datetime.datetime(2017,9,14,0,0)`` to ISO format,
      e.g. ``2017-09-14``
  
      :param date: datetime instance to convert
      :type date: datetime
      :param only_date: whether to return date only or also time information. Default is ``True``
      :type only_date: bool
      :return: date in ISO 8601 format
      :rtype: str