chetan buye
chetan buye

Reputation: 37

Add a specific amount of time to a datetime column

i am using pandas.Timestamp.now(tz='America/New_York') to get the current time.

and using pandas.Timestamp.now(tz='America/New_York').date() to get current date

But I wanted to add 9hr 30min to the current date

pandas.Timestamp.now(tz='America/New_York').date() + pandas.Timedelta('570 minutes') 

the following code is just giving date without the 9 hrs 30 minutes . Where should I improve ?

Upvotes: 1

Views: 73

Answers (1)

cs95
cs95

Reputation: 402493

You probably meant to call normalize before adding the two:

i = pandas.Timestamp.now(tz='America/New_York').normalize() 
j = pandas.Timedelta('570 minutes')

print(i + j) 
Timestamp('2018-06-05 09:30:00-0400', tz='America/New_York')

Upvotes: 3

Related Questions