Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
4 Respostas
9359 Visualizações

If we will take date max in this month, can use this code :

 

date_now = datetime.today()
date_max = date_now.max.day

 

But how to take date max in next month?

Avatar
Cancelar
Melhor resposta

Hi,

Try like below code.

from odoo.tools import date_utils

def max_date(self):
today = fields.date.today()
next_month = date_utils.add(today, months=1)
date_max = date_utils.end_of(next_month , "month")

Regards

Avatar
Cancelar
Melhor resposta

You can try following code to get next month's last day:

import datetime

from dateutil.relativedelta import relativedelta

next_month_max_day =((datetime.datetime.today().date() + relativedelta(months=+1,day=31))).day

Avatar
Cancelar
Melhor resposta

import calendar
date_now = datetime.today()
day_max = calendar.monthrange(date_now.year, date_now.month +1 )[1]  # return tuple( 1.st day, number of days)

hope it helps

Avatar
Cancelar
Melhor resposta

Try this,

from dateutil.relativedelta import relativedelta
from datetime import datetime
next_month = datetime.today() + relativedelta(months=1)
date_max=next_month.max.day

Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
3
jun. 25
681
1
jul. 23
3400
2
abr. 21
3444
1
out. 18
4784
1
out. 16
4221