How can I know if a date is prior to today?

Paul McGuire ptmcg at
Wed Mar 25 14:43:38 CET 2009

On Mar 25, 8:31 am, "Giampaolo Rodola'" <gne... at> wrote:
> Hi,
> I have a date expressed in seconds.
> I'd want to pretty print it as "%H:%M" if the time refers to today and
> "%b%d" (month, day) if it's of yesterday or before.

Use datetime module.

import time
from datetime import datetime
now = time.time()
thisTimeYesterday = now - 24*3600

print datetime.fromtimestamp(now) <
print datetime.fromtimestamp(thisTimeYesterday) <

-- Paul

More information about the Python-list mailing list