How split N days between specified start & end days - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How split N days between specified start & end days (/thread-37064.html) |
How split N days between specified start & end days - SriRajesh - Apr-28-2022 Hi, I have start date and end date. I want to split it to N-equal days. start_date = "2022/04/10 00:00:00" end_date = "2022/04/14 00:00:00" I want to make list of N-equal days ["2022/04/10 00:00:00", "2022/04/11 00:00:00", "2022/04/12 00:00:00","2022/04/13 00:00:00", "2022/04/14 00:00:00"]. Some one can help how to achieve this. Interval of days may be 1, or 2, x. RE: How split N days between specified start & end days - snippsat - Apr-28-2022 When you have task like this you most give it try to show some effort🔨 Can do it with datatime (a little more work) or Pandas pandas.date_range or my favorite Pendulum range(). >>> import pendulum >>> >>> start_date = "2022/04/10 00:00:00" >>> start_date = "2022/04/10 00:00:00" >>> # Parse it to Datetime object >>> start_date = pendulum.parse(start_date) >>> end_date = pendulum.parse(end_date) >>> period = pendulum.period(start_date, end_date) >>> for dt in period.range('days'): ... print(dt) ... 2022-04-10T00:00:00+00:00 2022-04-11T00:00:00+00:00 2022-04-12T00:00:00+00:00 2022-04-13T00:00:00+00:00 2022-04-14T00:00:00+00:00 RE: How split N days between specified start & end days - SriRajesh - May-06-2022 thanks |