datetime.date.today().isocalendar()[0]
sábado, 21 de mayo de 2011
Python, más aritmética con meses
def suma_mes(current_date, month_step):
""" suma month_setp mesos a current_date """
carry, new_month=divmod(current_date.month-1+month_step, 12)
new_month+=1
return current_date.replace(year=current_date.year+carry, month=new_month)
¿Cuántos días faltan para el mismo día de hoy del mes que viene?
>>> print (suma_mes(datetime.date.today(), 1)-datetime.date.today()).days
Sumar un mes con python
>>> from datetime import date
>>> current_date=date.today()
>>> carry, new_month=divmod(current_date.month-1+1, 12)
>>> new_month+=1
>>> current_date=current_date.replace(year=current_date.year+carry, month=new_month)
>>> print date.today()
2011-05-21
>>> print current_date
2011-06-21
>>>
Suscribirse a:
Entradas (Atom)