Python Forum
TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'float'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'float'
#1
Hi all,

I am working on datetime.datetime objects to calculating between 19:00 and 22:15. I want to calculating the datetime objects and then multiply by the value 11.4.

When I try this:

program_time = program_stop_time - program_start_time program_duration = program_time * 11.4
I will get an error: TypeError: unsupported operand type(s) for *: 'datetime.timedelta' and 'float'


Here it is the input for the variables:

program_start_time:

2018-05-01 19:00:00
program_stop_time:

2018-05-01 22:15:00
Here is the return output when I calculating:

3:15:00
Here is the code:

start_time = time.strptime(program_start_date, '%Y%m%d%H%M%S') program_start_time = datetime.datetime.fromtimestamp(time.mktime(start_time)) stop_time = time.strptime(program_stop_date, '%Y%m%d%H%M%S') program_stop_time = datetime.datetime.fromtimestamp(time.mktime(stop_time)) program_duration = program_stop_time - program_start_time
Here is what I want to achieve:

3591
Can you please help me how to correct the error to allow me to calculating the datetime object and multiply the value to get the return output I want??
Reply
#2
something like this?
>>> import datetime >>> import time >>> start_time = datetime.datetime.now() >>> end_time = datetime.datetime.now() >>> start_time datetime.datetime(2018, 5, 1, 15, 15, 17, 872088) >>> end_time datetime.datetime(2018, 5, 1, 15, 15, 25, 640901) >>> elapsed_time = end_time - start_time >>> ts = elapsed_time.total_seconds() * 11.4 >>> ts 88.5644682 >>>
Reply
#3
(May-01-2018, 07:08 PM)chris0147 Wrote: Here is what I want to achieve:
3591

But what is that? Hours? Minutes? Seconds?
It's an unsupported operation, because multiplying a complex timespan by 11.4 doesn't make sense.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unsupported datetime format code clamadv 3 512 Oct-08-2025, 08:26 PM
Last Post: snippsat
Question TypeError: argument of type 'NoneType' is not iterable Tajaldeen 7 6,156 Nov-29-2024, 09:45 AM
Last Post: Tajaldeen
  python calculate float plus float is incorrect? sirocawa 6 3,147 Apr-16-2024, 01:45 PM
Last Post: DeaD_EyE
  Type Error: Unsupported Operand jhancock 2 7,208 Jul-22-2023, 11:33 PM
Last Post: jhancock
  TypeError: 'float' object is not callable #1 isdito2001 1 2,528 Jan-21-2023, 12:43 AM
Last Post: Yoriz
  Write Null values as 0.0 (float) type in csv mg24 3 3,349 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  TypeError: 'float' object is not callable TimofeyKolpakov 3 4,739 Dec-04-2022, 04:58 PM
Last Post: TimofeyKolpakov
  TypeError: unsupported operand type(s) for +: 'dict' and 'int' nick12341234 1 12,551 Jul-15-2022, 04:04 AM
Last Post: ndc85430
  TypeError: float() argument must be a string or a number, not 'list' Anldra12 2 7,816 Jul-01-2022, 01:23 PM
Last Post: deanhystad
  TypeError: unsupported opperand type(s) for %: 'int' and 'list' cool_person 7 4,655 May-07-2022, 08:40 AM
Last Post: ibreeden

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.