In Python, how to I create a datetime with X hours?

datetime, python, time

Solution

from datetime import datetime, timedelta

def hours_ago(hours):
    return datetime.today() - timedelta(hours=hours)

def days_ago(days):
    return datetime.today() - timedelta(days=days)

Problem

How do I create the datetime that is 24 hours before NOW()? 48 before NOW()? X hours or days before now??

Original source

Related problems