Odoo Help

0

How to display all dates between two dates ?

By
Undan
on 5/18/16, 2:11 AM 522 views

When two dates are given for eg: start date-: 05/01/2016 end date : 05/03/2016 ..from january to march ..i want to display all the dates between these two dates.

3

Anil R. Kesariya

--Anil R. Kesariya--
4543
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
Anil R. Kesariya
On 5/18/16, 2:42 AM

Undan,

Here you Go!

import datetime
t_date = datetime.datetime.today()
num_of_day = 10 # This is different between two date range, you just find difference and use as numb_of_day

date_list = [base - datetime.timedelta(days=x) for x in range(0, num_of_day)]
print "Day List in Datetime Format:",date_list

This might help you,

Regards,

Anil.

1

Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
904
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.

https://www.linkedin.com/profile/public-profile-settings?trk=prof-edit-edit-public_profile

tibrahim@2p.com.sa

Tarek Mohamed Ibrahim
On 5/18/16, 2:55 AM

use the following function, it is based on using the 'timedelta' 


from datetime import datetime, timedelta

#show dates between two dates

def get_date_list(date1, date2):

    date_list = []

    loop_dt = date1

    print loop_dt

    while loop_dt < date2:

        loop_dt = loop_dt + timedelta(days=1)

        print loop_dt


get_date_list( datetime(2016,1,5), datetime(2016,03,5))


you can change it to return a list of dates

1
Deepak Krishna
On 5/18/16, 2:46 AM
 
fmt = '%Y-%m-%d'
d1 = datetime.strptime(from_date, fmt)
d2 = datetime.strptime(to_date, fmt)
dates_btwn = d1
while dates_btwn <= d2:   
    print "dates_between=========>>>",dates_btwn.date()
    dates_btwn = dates_btwn + relativedelta.relativedelta(days=1)

This will display the dates between two dates..Hope this will help You..

0
Neha Patel (nat)
On 1/19/17, 7:45 AM

from datetime import date, timedelta as td

dt1 = date(2016, 7, 10)

dt2 = date(2016, 7, 19)

delta = dt2 - dt1

for i in range(delta.days + 1):

    print dt1 + td(days=i)



i hope it might help you

0

import datetime

today = datetime.datetime.today()

numdays = 10

date_list = [today - datetime.timedelta(days=x) for x in range(0, numdays)]

print 'date_list',date_list

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: 5/18/16, 2:11 AM
Seen: 522 times
Last updated: 1/19/17, 7:45 AM