The obvious way to do this is datetime . But you apparently want to avoid this for some strange reason. Well, you can use time or calendar , or various third-party libraries, or your own code instead.
Here it is with time :
import time def yesterday(): now = time.time() yesterday = time.localtime(now - 86400)
If you run this during the leap second, on a platform that tracks the leap seconds, it will give today, not yesterday. You can check it easily (basically, if today == yesterday, subtract another day), but I don't think it's worth it.
Also, if you run this during DST cross-docking in the time zone, where the crossover occurs between midnight and 01:00 or 23:00 (depending on your hemisphere), it will receive the wrong day. For example, in Brazil , if you run this code during the second 23: 00-00: 00 hours on February 16, 2013, it will return the beginning of the day, which includes the time 24 hours ago ... which is today, not yesterday. The same workaround works here.
source share