code: def get_date_range(dates, separator='-'):
      
      if isinstance(dates, str) and dates.isdigit():
          y = dates[:4]
          m = dates[4:]
          if (len(y) != 4) or (not 1 <= int(m) <= 12):
              raise (ValueError("date must be a date string like '201806', but get {}".format(dates)))
      elif hasattr(dates, 'year') and hasattr(dates, 'month'):
          y = str(dates.year)
          m = str(dates.month)
      else:
          raise (TypeError("date except a years string like '201806' or a object has 'year' "
                           "and 'month' attribute, but get a {}".format(type(dates))))
      
      # set month to length 2 if month less than 10
      m = '0'+m if len(m) != 2 else m
      
      mr = calendar.monthrange(int(y), int(m))
      
      first_day = separator.join([y, m, '1'])
      last_day = separator.join([y, m, str(mr[1])])
  
      return first_day, last_day
docs: 获取某个月的日期范围，返回该月第一天和最后一天的字符串表示
      
      :param:
          * dates: (string 或者 datetime obj) 月份信息
          * separator: (string) 分隔符，默认为 '-'
      :return:
          * first_day: (string) 该月份的第一天
          * last_day: (string) 该月份的最后一天
  
      举例如下::
  
          print('--- get_date_range demo ---')
          now_time = datetime.now()
          print(get_date_range(now_time))
          print(get_date_range('201802',separator='/'))
          print('---')
  
      执行结果::
  
          --- get_years demo ---
          ('2018-06-1', '2018-06-30')
          ('2018/02/1', '2018/02/28')
          ---