-1

I'm new to Python.

Would like to know how to create a timestamp variable.

list_compute_date[0:10]
Out[23]: 
[Timestamp('2021-05-04 00:00:00'),
 Timestamp('2021-04-29 00:00:00'),
 Timestamp('2021-04-28 00:00:00'),
 Timestamp('2021-04-27 00:00:00'),
 Timestamp('2021-04-26 00:00:00'),
 Timestamp('2021-04-23 00:00:00'),
 Timestamp('2021-04-22 00:00:00'),
 Timestamp('2021-04-20 00:00:00'),
 Timestamp('2021-04-19 00:00:00'),
 Timestamp('2021-04-16 00:00:00')]

I have the list_compute_date as above, now I would to create a variable as below:

today = Timestamp('2021-04-28 00:00:00')

and then:

x = list_compute_date[0] - today

print(x) is 6 days.

Please help. Thanks!

hexerei software
  • 3,100
  • 2
  • 15
  • 19

1 Answers1

2
from datetime import datetime

timestamp = datetime.now()
print('timestamp:', timestamp)

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