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.
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
This question has been flagged
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_daydate_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.
def dates_between_str_dates(self, date1, date2, mode='date'):
date_from = fields.Date.from_string(date1)
date_to = fields.Date.from_string(date2)
delta = date_to - date_from
if delta.days < 0:
return None
res = []
for n in range(delta.days + 1):
if mode == 'date':
res.append(date_from + timedelta(days=n))
if mode == 'string':
res.append(fields.Date.to_string(date_from + timedelta(days=n)))
return res
Add this function. Parameter mode is to specify output type string/date.
Thanks !
hi, in XML report, how can I display all the dates in that range(start_date to end_date)?
You can call python function from Qweb Like ..
<tr t-foreach="o.dates_between_str_dates(o.date_from,o.date_to)" t-as="each_date">
Thank you so much..This was so helpful.
Hi, any idea how to display net sales for each day in the report
orders = self.env['pos.order'].search([('date_order', '>=', docs.date_from),
('date_order', '<=', docs.date_to)])
for order in orders:
net_sales += order.amount_total
but in xml report,for me it is displaying the total net sales of that range in all dates of that range,but i want to display net_sales per date.How can i display net sales per date?
Thanks in advance
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..
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
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
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
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up