Home

Date generation in Python


Without any funky modulo crap on your part! Python is a bit strict on type conversions oppposed to PHP and also requires a strict format (9 item tuple) to generate Epoch timestamps. Anyways, in PHP I would do something like this:

for($i=0;$i\<60;$i++) { $date = mktime(0,0,0,date("m"),date("d")-1,date("Y")); echo date("m/d/Y",$date)."\n" }

and I was able to replicate that in Python with this:

for i in range(60): records = [] t = int(strftime("%Y")),int(strftime("%m")),int(strftime("%d"))-i, \ 0,0,0,0,0,-1 timestamp = mktime(t) print strftime("%m/%d/%Y",localtime(timestamp))