I want to predict temperature when time (datetime type, hourly data for five months) and humidity is given. Before starting in python, I created a regression model in excel. But instead of predicting temperature, it gives date as an answer. On looking up the internet, I found that one can not do regression with datetime format. So some sources I looked upon have used datetime.toordinal() to convert dates to numerical Gregorian value. But my problem has date and time together. Will this method work with time too? If yes, how does it convert datetime? I need an efficient way to deal with datetime here, since it is vital in predicting the temperature being highly dynamic.
In order to run this regression you will have to encode the datatime column to a format a regressor can understand. When the granularity is large (e.g. daily or more) it can be done by simply adding an incrementing number to a 'time' column. A more rigorous way would be to extract features from the date, such as hour, day, and month. You can read more in this answer.
Note that as Jon stated, your model will not generalize well if there is a seasonal component to it.