Python: get datetime of last hour

You can achieve the same goal using pandas:

import pandas as pd
pd.Timestamp.now() - pd.Timedelta('1 hours')

This works for me:

import datetime

lastHourDateTime = datetime.datetime.now() - datetime.timedelta(hours = 1)
print(lastHourDateTime.strftime('%Y-%m-%d %H'))

# prints "2011-09-28 12" which is the time one hour ago in Central Europe

Date doesn't have the hour - use datetime:

from datetime import datetime, timedelta
last_hour_date_time = datetime.now() - timedelta(hours = 1)
print(last_hour_date_time.strftime('%Y-%m-%d %H:%M:%S'))