Junaid Mohammad
Junaid Mohammad

Reputation: 477

how to convert a python date in to an integer

Struggling with something that should be easy:

today = '26/8/2018'
start = '1/8/2018'
diff = today - start

diff gives us 26 days

how do I take the integer value of this datetime? i.e. 26?

basically, im trying to calc a daycount fraction, (diff / 365) * 10,000 say, but it wont work.

My actual values I have are:

0       304.548
1       371.397
2       350.466
3      -3574.36
4       255.452

and im trying to multiply them by: duration

0     13 days      
1     2 days       
2     1 days         
3     20 days       
4      7 days 

But I get:

0       TimedeltaIndex(['3959 days 02:57:32.054794',  ...
1       TimedeltaIndex([ '4828 days 03:56:42.739725', ...
2       TimedeltaIndex([ '4556 days 01:18:54.246575', ...
3       TimedeltaIndex(['-46467 days +08:52:36.164383'...
4       TimedeltaIndex(['3320 days 21:02:27.945204',  ...

desired output is 0 3959.124 as an integer (304.548*13), not as a daycount

Upvotes: 0

Views: 420

Answers (1)

Ashish Acharya
Ashish Acharya

Reputation: 3399

Perhaps something like this might work:

In [1]: import datetime

In [4]: diff = datetime.datetime.today() - datetime.datetime(year=2018, month=8, day=1)

In [5]: diff.days
Out[5]: 25

Then you can do something like:

In [10]: diff.days / 365 * 10000
Out[10]: 684.931506849315

Upvotes: 2

Related Questions