# Python script - datetime conversion list

**URL:** <https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898>\
**Category:** Revit\
**Created:** [July 13, 2020, 10:19am UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898 "2020-07-13T10:19:17Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![paolo.pozzoli](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@paolo.pozzoli](https://forum.dynamobim.com/u/paolo.pozzoli)\
**Post date:** [July 13, 2020, 10:19am UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/1 "2020-07-13T10:19:17Z")

</div>

Hi there,  
I’m new to Dynamo and to Python scripts as well.  
I’m creating a Dynamo routine to create sheets in Revit from data in an Excel file.  
I wish to set some sheets parameters as well (Drawn By, Designed By, etc).  
Each Excel column contains all data for one variable (i.e. Drawn By), so I get several Dynamo lists to be fed into Revit.  
When it comes to Sheet Issue Date I get dates formatted like “11/07/2020 00.00.00” and I want to reformat them to something like “11-07-2020”.  
I tried to create a Dynamo script with `datetime.strptime(*originalData*, "%d/%m/%Y").strftime(str_format)`.  
It performs good if I feed in to Python Script a single string, but I’m struggling to do the same with all the values from within a list.  
Following the Python code and a screenshot:

```
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from datetime import datetime

# The inputs to this node will be stored as a list in the IN variables.

# Place your code below this line
str_format = IN[0]
myDatesList = IN[1]

myNewDatesList = []

# Assign your output to the OUT variable.

for d in myDatesList:
	myNewDatesList.append(datetime.strptime(d, "%d/%m/%Y").strftime(str_format))

OUT = myNewDatesList

```

Thank you in advance for your support.  
Best regards,  
PP

 ![Python_ReformatListOfDates](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/0/90d839ce0679bf7dab5136bc7a53535140afb1a9.jpeg)

---

<div class="post-metadata">

**Author:** ![Brendan\_Cassidy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/brendan_cassidy/32/7685_2.png) [@Brendan\_Cassidy](https://forum.dynamobim.com/u/Brendan_Cassidy)\
**Post date:** [July 13, 2020, 11:13am UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/2 "2020-07-13T11:13:55Z")

</div>

What does the yellow error say for the python node?

---

<div class="post-metadata">

**Author:** ![paolo.pozzoli](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@paolo.pozzoli](https://forum.dynamobim.com/u/paolo.pozzoli)\
**Post date:** [July 13, 2020, 11:28am UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/3 "2020-07-13T11:28:54Z")

</div>

![Python_ReformatListOfDates_Error](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/b/fb065b8663e3a500107ae182f78bfb7cf8653342.jpeg)

Row 27: it expects a string but I passed a datetime.  
Don’t know how to fix it.  
Should I convert the value to string?

Thank you

---

<div class="post-metadata">

**Author:** ![Brendan\_Cassidy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/brendan_cassidy/32/7685_2.png) [@Brendan\_Cassidy](https://forum.dynamobim.com/u/Brendan_Cassidy)\
**Post date:** [July 13, 2020, 11:54am UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/4 "2020-07-13T11:54:29Z")

</div>

Yeah the inputted date seems to want to be a string not a “DateTime” element. Therefore add a “.ToString()” to end of the “d”.

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/4/54e8c661a22a34a13254961e09153dc93fc256f8.png)

---

<div class="post-metadata">

**Author:** ![paolo.pozzoli](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@paolo.pozzoli](https://forum.dynamobim.com/u/paolo.pozzoli)\
**Post date:** [July 13, 2020, 12:05pm UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/5 "2020-07-13T12:05:04Z")

</div>

Thank you Brendan,  
I tried your suggestion and the type mismatch was solved.  
However I still get an error for the format now

```
ValueError: time data does not match format
data= **12/07/2020 00.00.00** , fmt=%d/%m/%Y, to: d'/'M'/'yyyy

```

The date between asterisks is in the format I get from my Excel file (see first pic I uploaded, in the list of retrieved data below the “SheetIssueDate List.GetItemAtIndex” node).

Thanks again.

---

<div class="post-metadata">

**Author:** ![Brendan\_Cassidy](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/brendan_cassidy/32/7685_2.png) [@Brendan\_Cassidy](https://forum.dynamobim.com/u/Brendan_Cassidy)\
**Post date:** [July 13, 2020, 12:09pm UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/6 "2020-07-13T12:09:57Z")

</div>

> [@paolo.pozzoli](#):
>
> `ValueError: time data does not match format`

Your string format of %d%m%Y does not match the inputted date and time format “12/07/2020 00.00.00”

You should have it as “%d%m%Y %H:%M:%S”

Therefore :  
datetime.strptime(d, “%d%m%Y”)

Becomes:  
datetime.strptime(d.ToString(), “%d%m%Y %H:%M:%S”)

---

<div class="post-metadata">

**Author:** ![paolo.pozzoli](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@paolo.pozzoli](https://forum.dynamobim.com/u/paolo.pozzoli)\
**Post date:** [July 13, 2020, 12:13pm UTC](https://forum.dynamobim.com/t/python-script-datetime-conversion-list/52898/7 "2020-07-13T12:13:12Z")

</div>

Thanks again Brendan!  
By the time I wrote my previous post I figured it out myself by reading the [https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior](https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior)

I changed the code as following and now it works like a charm  
`myNewDatesList.append(datetime.strptime(d.ToString(), "%d/%m/%Y %H.%M.%S").strftime(str_format))`

Thanks again for your support.  
Best regards.
