Python Forum
How split N days between specified start & end days
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How split N days between specified start & end days
#1
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.
Reply
#2
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 
SriRajesh likes this post
Reply
#3
thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  filter every 24 days file (considering file name) RolanRoll 5 1,041 Jun-23-2022, 11:41 AM
Last Post: RolanRoll
  How to plot intraday data of several days in one plot mistermister 3 1,937 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  splitting total time between days tester_V 7 1,929 Nov-14-2020, 04:40 AM
Last Post: tester_V
Brick How To Sum Numbers Of Next 7 Days Developer_2018 7 1,828 Oct-19-2020, 02:54 PM
Last Post: Developer_2018
  How to print n days back date at give time Mekala 1 1,365 Oct-10-2020, 03:35 AM
Last Post: bowlofred
  Make list of dates between today back to n days Mekala 3 1,531 Oct-03-2020, 01:01 PM
Last Post: ibreeden
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 1,417 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  coding has run for 7 days but still yet to got any result? syhue2 3 1,725 Jun-21-2020, 12:41 PM
Last Post: Larz60+
  remove files from folder older than X days kerzol81 2 7,223 Jan-03-2020, 11:55 PM
Last Post: snippsat
  'Age' categorical (years -months -days ) to numeric Smiling29 4 2,067 Oct-17-2019, 05:26 PM
Last Post: Smiling29

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020