Get yesterday's date

Mike C. Fletcher mcfletch at rogers.com
Wed Nov 27 05:31:39 EST 2002


mxDateTime is often used (and is probably the easiest approach):

 >>> from mx.DateTime import *
 >>> now()
<DateTime object for '2002-11-27 05:27:05.00' at 1630918>
 >>> now()+ RelativeDateTime( days=-1, hour=0, minute=0, second=0 )
<DateTime object for '2002-11-26 00:00:00.00' at 16880c0>
 >>> now()+RelativeDateTime( days=-1 )
<DateTime object for '2002-11-26 05:28:40.00' at 16881d0>
 >>> (now()+ RelativeDateTime( days=-1, hour=0, minute=0, second=0 
)).ticks()
1038286800.0

http://www.egenix.com/files/python/mxDateTime.html

HTH,
Mike

Michel COMBE wrote:

>Hi,
>
>I need to run a SQL query on a MySQL database to get yesterday's records.
>How do I specify "yesterday" ?
>Isn't there some kind of date arithmetic in Python or should I use an
>external library ?
>Which library ?
>
>Thanks for your answer
>
>Michel COMBE
>
>
>  
>

-- 
_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/







More information about the Python-list mailing list