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

Hi guys,

I have 3 fields:

  • date_n(datetime), time(00:00:00) and date_result (computed field)

And 2 buttons:

  • "Start" and "Stop"

When I click on the Start button, the time field start counting... and when I click on Stop button, the field date_result will store date_n + time in format like d/m/Y 00:00:00


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

Anybody help :)

Câu trả lời hay nhất

Hi,

You can refer how the stop time is calculated for an event using start time and event duration in the calendar module.In this case this will be simple because there are 2 datetime fields and a duration field - time in your case.

date_result = date_n + timedelta(minutes=round((time or 1.0) * 60))

Either you can compute total time if it is not a field of type float by the following method by storing the start time and end time.

tot_sec = (end_time - start_time).total_seconds()
tot_hours = round((tot_sec / 3600.0), 2)

Regards

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 22
4193
1
thg 4 22
3269
1
thg 3 22
4139
1
thg 2 22
2462
0
thg 2 22
2223