Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
12877 Lượt xem

Hey all! I am facing this issue while using strptime. But as i can see in my code i am unable to find what i am doing wrong kindly please help with these 3 lines. error is generated from "new_date"


new_date_time = str(day_dict[0].date) + ' ' + hour
new_date = datetime.strptime(new_date_time, '%Y-%m-%d %H:%M:%S')
self.create_inverse_attendance(day_dict[0].employee_id, action, new_date)
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

It seems the date time value is wrong, in the error message it can be seen that your date time is 2019-10-08 18:60:00 , which actually it has to be 2019-10-08 19:00:00 , 60 Minutes has to be counted as an hour right ?

You are getting the error message because in the date time format, the value for %M is 0-59

Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

The date you are trying to convert "2019-10-08 18:60:00", in the hour you have the minute 60, which is not correct since it only corresponds to 0-59, for example:

new_date = datetime.strptime('2019-10-08 18:59:00','%Y-%m-%d %H:%M:%S')

 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 22
5926
1
thg 8 21
7895
1
thg 8 21
5734
1
thg 8 21
6476
2
thg 3 24
2633