Dear Team, I am trying to get the dates between start and end date coming from view params, I am using value change script. Can someone guide me please
So, given 2024-07-01 and 2024-07-05, you would want:
2024-07-02
2024-07-03
2024-07-04
?
Yes you are right @nminchin
I'd probably do something like:
days = [system.date.addDays(start_date, d) for d in xrange(system.date.daysBetween(start_date, end_date))]
But also, why ?
1 Like
I haven't tried this, May I know does the output gives me the dates between two date
I'll break this up for you:
system.date.daysBetween(start_date, end_date)
This will return the number of days between 2 dates- xrange(n)
This generates a list of numbers from 0 to n (including 0, excluding n) [something(x) for x in iterable]
That's a list comprehension. It appliessomething
to everyx
in an iterable, and makes a list from thosesystem.date.addDays(start_date, n)
This returns a date that'sn
days after the start date
To sum it up: This will generate a new date by adding x days to the start date, for every x up to the number of days between 2 dates.
So, yes, it will return the dates between two dates.
4 Likes
Thanks for the explanation @pascal.fragnoud