[pyar] Calcular ultimo Domingo de este mes

Facundo Batista facundobatista en gmail.com
Mar Ago 30 07:34:52 ART 2011


On Tue, Aug 30, 2011 at 2:50 AM, Juan Carlos Ojeda
<juancarlospaco en gmail.com> wrote:

> me devuelva el ultimo Domingo del corriente mes, como harian ustedes ...?

>>> from dateutil.rrule import rrule, MONTHLY, SU
>>> import datetime
>>> primdiames = datetime.date(2011, 8, 1)
>>> rule = rrule(MONTHLY, byweekday=(SU(-1),), count=1, dtstart=primdiames)
>>> list(rule)[0]
datetime.datetime(2011, 8, 28, 0, 0)

Si querés todos los últimos domingos del año...

>>> diauno = datetime.date(2011, 1, 1)
>>> rule = rrule(MONTHLY, byweekday=(SU(-1),), count=12, dtstart=diauno)
>>> for fecha in rule:
...   print fecha
...
2011-01-30 00:00:00
2011-02-27 00:00:00
<cortado>

Y así.

"rrule" es poderosísimo: http://labix.org/python-dateutil

Slds.

-- 
.    Facundo

Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/



More information about the pyar mailing list