0

I'm working on amping up the Python skills (I work heavy in R) and I'm trying to replicate the creation of a list of dates in python in iso format for passing as strings into a sql server connection:

here is the list:

#step 1:create date list
base = datetime.datetime(2017, 3, 31)
date_list = [base - datetime.timedelta(days=x) for x in range(0, 90)]
**strong text**

now how do I turn it into an iso like this:

base.strftime('%Y-%m-%d')

but retain the list element, so change the entire list in date_list into iso formats?

LoF10
  • 1,907
  • 1
  • 23
  • 64
  • Clarifying question: you want to convert the current items in `date_list` to iso format of `'%Y-%m-%d'`. Is that right? – Jarad Sep 04 '18 at 16:23
  • yes correct, if there is a better way of approaching this than the code provided above I am open to suggestions – LoF10 Sep 04 '18 at 17:22

1 Answers1

0

I have actually found the answer for anyone interested:

#apply a different function across lists
date_strings = [dt.strftime('"%Y-%m-%d"') for dt in date_list]

comes from: Python: create human-friendly string from a list of datetimes

LoF10
  • 1,907
  • 1
  • 23
  • 64