using calendar.monthrange(year, month)
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
Hi,
You can try the following code.
from odoo.tools import date_utils
def _prvs_mnth_dates(self):
today = fields.date.today()
previous_month = date_utils.subtract(today, months=1)
starting_prevs_month = date_utils.start_of(previous_month, "month")
ending_prevs_month = date_utils.end_of(previous_month, "month")
Regards
Dear Mohammed Raihan,
You can find the previous months's first date and last date from current date by the following code:-
from datetime import date, timedelta
last_day_of_prev_month = date.today().replace(day=1) - timedelta(days=1)
start_day_of_prev_month = date.today().replace(day=1) - timedelta(days=last_day_of_prev_month.day)
# For printing results
print("First day of prev month:", start_day_of_prev_month)
print("Last day of prev month:", last_day_of_prev_month)
I hope this information has been useful to you and your error has been resolved after making this change.
Feel free for further assistance on contact@geminatecs.com.
Thank you
Geminate Consultancy Services
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อ