# How to randomly set values for the data type 'Date Time' in the Programmable Device Simulator

**URL:** <https://forum.inductiveautomation.com/t/how-to-randomly-set-values-for-the-data-type-date-time-in-the-programmable-device-simulator/75371>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [June 22, 2023, 12:46am UTC](https://forum.inductiveautomation.com/t/how-to-randomly-set-values-for-the-data-type-date-time-in-the-programmable-device-simulator/75371 "2023-06-22T00:46:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yuichi\_Sugiura](https://avatars.discourse-cdn.com/v4/letter/y/8491ac/32.png) [@Yuichi\_Sugiura](https://forum.inductiveautomation.com/u/Yuichi_Sugiura)\
**Post date:** [June 22, 2023, 12:46am UTC](https://forum.inductiveautomation.com/t/how-to-randomly-set-values-for-the-data-type-date-time-in-the-programmable-device-simulator/75371/1 "2023-06-22T00:46:57Z")

</div>

How to randomly set values for the data type 'Date Time' in the Programmable Device Simulator for device connections?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 22, 2023, 1:51am UTC](https://forum.inductiveautomation.com/t/how-to-randomly-set-values-for-the-data-type-date-time-in-the-programmable-device-simulator/75371/2 "2023-06-22T01:51:51Z")

</div>

This script seems to work:

```auto
import random
from datetime import datetime, timedelta
startDate = datetime(2023, 1, 1)
endDate = datetime(2023, 12, 31)
randomDate = startDate + timedelta(days=random.randint(0, (endDate - startDate).days))
print randomDate

```

**Outputs:**

```auto
2023-01-14 00:00:00
2023-08-27 00:00:00
2023-08-08 00:00:00
2023-03-03 00:00:00
2023-04-15 00:00:00

```

---

<div class="post-metadata">

**Author:** ![Yuichi\_Sugiura](https://avatars.discourse-cdn.com/v4/letter/y/8491ac/32.png) [@Yuichi\_Sugiura](https://forum.inductiveautomation.com/u/Yuichi_Sugiura)\
**Post date:** [July 21, 2023, 6:28am UTC](https://forum.inductiveautomation.com/t/how-to-randomly-set-values-for-the-data-type-date-time-in-the-programmable-device-simulator/75371/3 "2023-07-21T06:28:59Z")

</div>

My apologies for the delayed response.  
It is working with the Gateway Event Script.  
Thank you for the explanation.
