Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
9626 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Try this,

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
มิ.ย. 25
973
1
ก.ค. 23
3677
2
เม.ย. 21
3698
1
ต.ค. 18
5045
1
ต.ค. 16
4479