Skip to content

Instantly share code, notes, and snippets.

@xergioalex
Created May 16, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xergioalex/54519249bc74ca29d6c249a94f6181c5 to your computer and use it in GitHub Desktop.
Save xergioalex/54519249bc74ca29d6c249a94f6181c5 to your computer and use it in GitHub Desktop.
Create lists of days between two days in python
from datetime import datetime
from datetime import timedelta
start = '6/29/19'
end = '6/20/20'
start_date = datetime.strptime(start, '%m/%d/%y')
end_date = datetime.strptime(end, '%m/%d/%y')
days_total = (end_date - start_date).days
days_list = []
tmp_date = start_date
for i in range(0, days_total):
tmp_date = tmp_date + timedelta(days=1)
days_list.append(tmp_date.strftime('%m/%d/%y'))
print(days_list)
print(len(days_list))
//
// Output
// ['06/30/19', '07/01/19', '07/02/19', '07/03/19', '07/04/19', '07/05/19', '07/06/19', '07/07/19', '07/08/19', '07/09/19', '07/10/19', '07/11/19', '07/12/19', '07/13/19', '07/14/19', '07/15/19', '07/16/19', '07/17/19', '07/18/19', '07/19/19', '07/20/19', '07/21/19', '07/22/19', '07/23/19', '07/24/19', '07/25/19', '07/26/19', '07/27/19', '07/28/19', '07/29/19', '07/30/19', '07/31/19', '08/01/19', '08/02/19', '08/03/19', '08/04/19', '08/05/19', '08/06/19', '08/07/19', '08/08/19', '08/09/19', '08/10/19', '08/11/19', '08/12/19', '08/13/19', '08/14/19', '08/15/19', '08/16/19', '08/17/19', '08/18/19', '08/19/19', '08/20/19', '08/21/19', '08/22/19', '08/23/19', '08/24/19', '08/25/19', '08/26/19', '08/27/19', '08/28/19', '08/29/19', '08/30/19', '08/31/19', '09/01/19', '09/02/19', '09/03/19', '09/04/19', '09/05/19', '09/06/19', '09/07/19', '09/08/19', '09/09/19', '09/10/19', '09/11/19', '09/12/19', '09/13/19', '09/14/19', '09/15/19', '09/16/19', '09/17/19', '09/18/19', '09/19/19', '09/20/19', '09/21/19', '09/22/19', '09/23/19', '09/24/19', '09/25/19', '09/26/19', '09/27/19', '09/28/19', '09/29/19', '09/30/19', '10/01/19', '10/02/19', '10/03/19', '10/04/19', '10/05/19', '10/06/19', '10/07/19', '10/08/19', '10/09/19', '10/10/19', '10/11/19', '10/12/19', '10/13/19', '10/14/19', '10/15/19', '10/16/19', '10/17/19', '10/18/19', '10/19/19', '10/20/19', '10/21/19', '10/22/19', '10/23/19', '10/24/19', '10/25/19', '10/26/19', '10/27/19', '10/28/19', '10/29/19', '10/30/19', '10/31/19', '11/01/19', '11/02/19', '11/03/19', '11/04/19', '11/05/19', '11/06/19', '11/07/19', '11/08/19', '11/09/19', '11/10/19', '11/11/19', '11/12/19', '11/13/19', '11/14/19', '11/15/19', '11/16/19', '11/17/19', '11/18/19', '11/19/19', '11/20/19', '11/21/19', '11/22/19', '11/23/19', '11/24/19', '11/25/19', '11/26/19', '11/27/19', '11/28/19', '11/29/19', '11/30/19', '12/01/19', '12/02/19', '12/03/19', '12/04/19', '12/05/19', '12/06/19', '12/07/19', '12/08/19', '12/09/19', '12/10/19', '12/11/19', '12/12/19', '12/13/19', '12/14/19', '12/15/19', '12/16/19', '12/17/19', '12/18/19', '12/19/19', '12/20/19', '12/21/19', '12/22/19', '12/23/19', '12/24/19', '12/25/19', '12/26/19', '12/27/19', '12/28/19', '12/29/19', '12/30/19', '12/31/19', '01/01/20', '01/02/20', '01/03/20', '01/04/20', '01/05/20', '01/06/20', '01/07/20', '01/08/20', '01/09/20', '01/10/20', '01/11/20', '01/12/20', '01/13/20', '01/14/20', '01/15/20', '01/16/20', '01/17/20', '01/18/20', '01/19/20', '01/20/20', '01/21/20', '01/22/20', '01/23/20', '01/24/20', '01/25/20', '01/26/20', '01/27/20', '01/28/20', '01/29/20', '01/30/20', '01/31/20', '02/01/20', '02/02/20', '02/03/20', '02/04/20', '02/05/20', '02/06/20', '02/07/20', '02/08/20', '02/09/20', '02/10/20', '02/11/20', '02/12/20', '02/13/20', '02/14/20', '02/15/20', '02/16/20', '02/17/20', '02/18/20', '02/19/20', '02/20/20', '02/21/20', '02/22/20', '02/23/20', '02/24/20', '02/25/20', '02/26/20', '02/27/20', '02/28/20', '02/29/20', '03/01/20', '03/02/20', '03/03/20', '03/04/20', '03/05/20', '03/06/20', '03/07/20', '03/08/20', '03/09/20', '03/10/20', '03/11/20', '03/12/20', '03/13/20', '03/14/20', '03/15/20', '03/16/20', '03/17/20', '03/18/20', '03/19/20', '03/20/20', '03/21/20', '03/22/20', '03/23/20', '03/24/20', '03/25/20', '03/26/20', '03/27/20', '03/28/20', '03/29/20', '03/30/20', '03/31/20', '04/01/20', '04/02/20', '04/03/20', '04/04/20', '04/05/20', '04/06/20', '04/07/20', '04/08/20', '04/09/20', '04/10/20', '04/11/20', '04/12/20', '04/13/20', '04/14/20', '04/15/20', '04/16/20', '04/17/20', '04/18/20', '04/19/20', '04/20/20', '04/21/20', '04/22/20', '04/23/20', '04/24/20', '04/25/20', '04/26/20', '04/27/20', '04/28/20', '04/29/20', '04/30/20', '05/01/20', '05/02/20', '05/03/20', '05/04/20', '05/05/20', '05/06/20', '05/07/20', '05/08/20', '05/09/20', '05/10/20', '05/11/20', '05/12/20', '05/13/20', '05/14/20', '05/15/20', '05/16/20', '05/17/20', '05/18/20', '05/19/20', '05/20/20', '05/21/20', '05/22/20', '05/23/20', '05/24/20', '05/25/20', '05/26/20', '05/27/20', '05/28/20', '05/29/20', '05/30/20', '05/31/20', '06/01/20', '06/02/20', '06/03/20', '06/04/20', '06/05/20', '06/06/20', '06/07/20', '06/08/20', '06/09/20', '06/10/20', '06/11/20', '06/12/20', '06/13/20', '06/14/20', '06/15/20', '06/16/20', '06/17/20', '06/18/20', '06/19/20', '06/20/20']
// 357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment