Python日期-TypeError:必须为整数(类型为str)

时间:2020-07-09 15:08:39

标签: python string date type-conversion typeerror

当我将日期作为参数传递时,出现以下错误。请你的建议。我有两个变量“ srartdate”和“ enddate”已作为参数传递。

from datetime import date

class classOne:

def getDateComp(self, startDate, EndDate=None):

    if EndDate is not None:
        sdate = date(startDate)
        edate = date(EndDate)
        print(sdate +" -- "+edate)
    else:
        print('No Date')

def main():
  objEQ = classOne()
  objEQ.getDateComp(startDate='2020, 7, 6', EndDate='2020, 7, 9')

if __name__ == "__main__":
    main()


 **Error:** 
    sdate = date(startDate)
    TypeError: an integer is required (got type str)

谢谢, 阿南德

0 个答案:

没有答案