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

Paul McGuire ptmcg at austin.rr.com
Wed Mar 25 14:43:38 CET 2009


On Mar 25, 8:31 am, "Giampaolo Rodola'" <gne... at gmail.com> 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) < datetime.today()
print datetime.fromtimestamp(thisTimeYesterday) < datetime.today()


-- Paul



More information about the Python-list mailing list