Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - merge time and date [duplicate]

Possible Duplicate:
Pythonic way to add datetime.date and datetime.time objects

This question seems quite simple for me but I can't find the answer.
I have a datetime.date() to which I'd like to add a datetime.time().

>>> import datetime
>>> my_time = datetime.time(9, 30)
>>> my_date = datetime.date(2012, 10, 2)

I tried

>>> my_time + my_date

I would have liked to get a

datetime.datetime(2012, 10, 2, 9, 30)

But the operand is not supported.
What is the best way to add my_time to my_date ?

like image 733
Pierre de LESPINAY Avatar asked Sep 28 '12 14:09

Pierre de LESPINAY


People also ask

How to merge two data sets in Python?

pd.merge(df1,df2) pd. merge() automatically detects the common column between two datasets and combines them on this column. In this case pd. merge() used the default settings and returned a final dataset which contains only the common rows from both the datasets.

How do I combine date and time columns in pandas?

Pandas Combine() Function combine() function which allows us to take a date and time string values and combine them to a single Pandas timestamp object. The function accepts two main parameters: Date – refers to the datetime. date object denoting the date string.

Which function is used to join 2 or more columns together to form a data frame?

We can join columns from two Dataframes using the merge() function. This is similar to the SQL 'join' functionality. A detailed discussion of different join types is given in the SQL lesson. You specify the type of join you want using the how parameter.


1 Answers

datetime.datetime.combine(datetime.date(2011, 01, 01), datetime.time(10, 23))

http://docs.python.org/release/2.6/library/datetime.html#datetime.datetime.combine

like image 165
dm03514 Avatar answered Nov 07 '22 23:11

dm03514