Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I am working on Odoo 10, in this i need to get dates of the day.
Eg: For the month "February" i want to print the "Date" which falls on "Monday". (i.e (05/02/2018, 12/02/2018, 19/02/2018, 26/02/2018 these dates are falls on monday) i need to print like this.)
can anyone guide me to achieve this.
Thanks in Advance.
Try this ,
import dateutil.rrule as rrule
from datetime import date
feb_date_list = list(rrule.rrule(rrule.WEEKLY,dtstart=date(2018,2,1),until=date(2018,2,28),byweekday=rrule.MO))
* By changing 'dtstart' and 'until' parameter you can do it for any month / year / duration.
Hope this will help you !
You could have done it by little R&D, googling.
Try following code:
from datetime import datetime
from calendar import monthrange
year = int(time.strftime('%Y'))
month = int(time.strftime('%m'))
for day in range(1, monthrange(year, month) + 1):
dt = datetime(year, month, day)
if dt.weekday() == 0: # 0 for Monday, 1 for Tue and so on....
Sudhir Arya ERP Harbor Consulting Services skype: firstname.lastname@example.org website: http://www.erpharbor.com
This question is rather about Python than just Odoo but to answer your question: you should use the Python packages date, datetime or calendar in order to get these values out. There are quite some ways to do this, but here is an example with the calendar package:
c = calendar.Calendar(firstweekday=calendar.MONDAY) year = 2018; month = 2 monthcal = c.monthdatescalendar(year,month) mondays = [day for week in monthcal for day in week if \ day.weekday() == calendar.MONDAY and \ day.month == month] for monday in mondays: print('monday: ' + str(monday))
Or an example with datetime:
today = datetime.date.today() day = datetime.date(today.year, today.month, 1) single_day = datetime.timedelta(days=1) mondays = 0 dates =  while day.month == today.month: if day.weekday() == 0: mondays += 1 dates.append(day) day += single_day print('Number of mondays this month:'+ str(mondays)) for date in dates: print('date: ' + str(date))
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 2/13/18, 7:16 AM|
|Seen: 375 times|
|Last updated: 2/27/18, 5:23 AM|