On Wednesday 05 August 2009 06:01:11 am adelaide_mike wrote:
> This should really be a Python enquiry, but I am sure someone will
> know:
>
> I need to calculate the date 12 weeks before today.  What is the best
> way?  TIA
>
> Mike
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups
> "Django users" group. To post to this group, send email to
> django-users@googlegroups.com To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com For more options, visit this
> group at http://groups.google.com/group/django-users?hl=en
> -~----------~----~----~----~------~----~------~--~---


The example should be pretty self explanatory and the docs will give you all 
the relative info.

You'll want to use datetime and datetime.timedelta

http://docs.python.org/library/datetime.html

and examples of using datetime and datetime.timedelta 

http://pleac.sourceforge.net/pleac_python/datesandtimes.html


Here's the example for figuring out 12 weeks in the past:

In [1]: import datetime

In [2]: now = datetime.datetime.now()

In [3]: diff = datetime.timedelta(weeks=12)

In [4]: past = now - diff

In [5]: past

Out[5]: datetime.datetime(2009, 5, 13, 6, 18, 12, 582151)


Mike

-- 
Any circuit design must contain at least one part which is obsolete, two parts
which are unobtainable, and three parts which are still under development.

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to