Odoo Help

0

To find the date of the day in odoo 10

By
Silviaa
on 2/13/18, 7:16 AM 153 views

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.

0
Dipak Shah
On 2/13/18, 8:03 AM
Hello \Silviaa,

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))

print feb_date_list

---------------------------------

* By changing 'dtstart' and 'until' parameter you can do it for any month / year / duration.

Hope this will help you !

Thanks,
Dipak.

Thank you, this works fine..

Silviaa
on 2/13/18, 11:29 PM
1

Sudhir Arya (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
11141
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

Top 10 Odoo contributor On Stackoverflow 

LinkedIn

Blog

Stackoverflow

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com 
Sudhir Arya (ERP Harbor Consulting Services)
On 2/13/18, 8:06 AM

Hi,

You could have done it by little R&D, googling.

Try following code:

import time
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] + 1):
dt = datetime(year, month, day)
if dt.weekday() == 0: # 0 for Monday, 1 for Tue and so on....
print dt

Sudhir Arya
ERP Harbor Consulting Services
skype: 
sudhir@erpharbor.com  website: http://www.erpharbor.com
0
Sehrish
On 2/19/18, 2:08 AM

Check out date manipulation in python

http://learnopenerp.blogspot.com/2018/01/python-date-manipulation.html

Use python strftime method to date and time formatting

http://learnopenerp.blogspot.com/2018/02/python-strftime-datetime-formatting.html

0

Yenthe

--Yenthe--
9108
| 8 8 8
Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 2/13/18, 8:03 AM

Hi Silviaa,

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:

import calendar

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:

import 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))

Regards,
Yenthe

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

Question tools

1 follower(s)

Stats

Asked: 2/13/18, 7:16 AM
Seen: 153 times
Last updated: 2/19/18, 2:08 AM