Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python-比较日期_Python_Date_Compare - Fatal编程技术网

python-比较日期

python-比较日期,python,date,compare,Python,Date,Compare,我正在写一份python作业,我们正在写一份酒店客户的房间预订。 我们应该比较到达和离开的日期。如果出发日期早于到达日期,它将打印错误消息,但我在运行它后不断收到错误消息。我不知道为什么……我正在尝试将客户信息命名为 预订=姓名双人('预订','确认房间\到达日期\离开日期\姓名) 所以我把到达日期(10/13/2008)去掉了,因为它是一个字符串,所以我把它拆分了。我试着把所有的数字加在一起作为一个整数。在那之后……我使用日期时间……是的……我好像做错了什么。我不理解错误的含义:基数为10的i

我正在写一份python作业,我们正在写一份酒店客户的房间预订。 我们应该比较到达和离开的日期。如果出发日期早于到达日期,它将打印错误消息,但我在运行它后不断收到错误消息。我不知道为什么……我正在尝试将客户信息命名为

预订=姓名双人('预订','确认房间\到达日期\离开日期\姓名)

所以我把到达日期(10/13/2008)去掉了,因为它是一个字符串,所以我把它拆分了。我试着把所有的数字加在一起作为一个整数。在那之后……我使用日期时间……是的……我好像做错了什么。我不理解错误的含义:基数为10的int()的文本无效

这是我的节目:

    elif lst[0]=='LR':
        for r in new_reservation_list:
            for d in r.arrive_date:
                lsst=d.split()
                month1=lsst[:2]
                months=int(''.join([str(x) for x in month1]))
                date1=lsst[3:5]
                dates=int(''.join(([str(x) for x in date1])))
                year1=lsst[7:]
                years=int(''.join(([str(x) for x in year1])))
            arrive_date1=datetime.date(int(months),int(dates),int(years))
            for e in r.depart_date:
                lstt=e.split()
                month2=lsst[:2]
                months2=int(''.join([str(x) for x in month2]))
                date2=lsst[3:5]
                dates2=int(''.join(([str(x) for x in date2])))
                year2=lsst[7:]
                years2=int(''.join(([str(x) for x in year2])))
            depart_date1=datetime.date(int(months2),int(dates2),int(years2))
            if arrive_date>depart_date==True:
                print('Sorry, can''t reserve room', r.room_number,' (',r.arrive_date,' to ',r.depart_date,'); can''t leave before you arrive.')
            elif lst[1] in new_reservation_list:
                    print('Sorry, can''t reserve room ',r.room_number, ' (',r.arrive_date,' to ',r.depart_date,'); it''s already booked (Conf. #',r.confirmation_number)
            else:
                print('Reserving room',r.room_number,'for',r.name,'-- Confirmation #',r.confirmation_number,'\n       ','arriving',r.arrive_date,', departing ',r.depart_date)
                print('{:5}{:8}{:16}{:15}{:25}'.format('No.','Rm.','Arrive','Depart','Guest'))
                print('{:5}{:4}{:12}{:12}{:17}'.format(r.confirmation_number,r.room_number,r.arrive_date,r.depart_date, r.name))

检查时间模块中的功能。您可以使用此函数转换日期并进行比较。

不建议用这种方式解析日期,请尝试使用正则表达式,错误发生在将字符串强制转换为int时。