Subtracting dates to get hours and minutes

Thomas Passin list1 at tompassin.net
Fri Dec 16 00:25:22 EST 2022


On 12/15/2022 11:34 PM, MRAB wrote:
> On 2022-12-15 22:49, Gronicus at SGA.Ninja wrote:
>> Yes, it works like a charm. On the tupility of it all.
>> Special thanks for the explanation too…..
>>
>>
>> (Originally asked but I found the errors. All is working)
>>
>> Now that the code no longer produces the errors, I see that the year 
>> and month not included in the calculation? How do I fix this?

First you should read about the function you are using.  In this case, 
it is at

https://docs.python.org/3.10/library/datetime.html

I found this page using an internet search for "python datetime.datetime".

All Python functions, classes, and methods will normally be found in the 
documentation for the standard library, as this one is.

You should also look at datetime.timedelta, as various people have 
posted here.  Try to understand what is being described.  Then try to 
make simple examples that will show if you can get what you want, or if 
not, what more information you need.  Look through the rest of the 
documentation of (in this case) the datetime module and see if any of 
the other functionality looks like it will produce what you want.

It is important to understand clearly what your input data is like, and 
what results you need to achieve.  If you are not clear, or do not 
express yourself clearly, it will be hard and frustrating for others on 
the list to assist you.

For example, you wrote "I see that the year and month not included in 
the calculation".  I don't know what you mean.  You already include the 
month in the tuple that you feed to datetime.datetime().  That is, in 
the input string you showed, "(2022, 12, 13,  5,  3, 30)", it seems that 
"2022" represents a year, "12" represents a month, "13" represents a day 
of the month, and so forth.

So I don't understand how year and month not included.  I see that you 
do think that something is not coming out right, but you need to be more 
precise about what you mean so that others can understand too.

To succeed at programming, you need to be very precise about attending 
to details because the computer cannot know what you have in your mind. 
To succeed at getting help, you have to be precise and accurate about 
what you want to achieve and what is not coming out right, and describe 
those things simply and clearly to other people.

In other words, please help us to help you.


More information about the Python-list mailing list