# Default value for DateTime Picker

**URL:** <https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177>\
**Category:** Ignition\
**Created:** [April 7, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177 "2022-04-07T15:54:16Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [April 7, 2022, 3:54pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/1 "2022-04-07T15:54:16Z")

</div>

I have a datetime parameter which i would like to default to the beginning of the current day, I have the idea to set that value using a startup script but I don’t know exactly how to write the code correctly or how to reference properties from the startup scripting page. Advice would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 7, 2022, 4:19pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/2 "2022-04-07T16:19:07Z")

</div>

Is this a vision or perspective question?

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [April 7, 2022, 4:19pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/3 "2022-04-07T16:19:19Z")

</div>

perspective

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 7, 2022, 4:22pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/4 "2022-04-07T16:22:11Z")

</div>

What does “beginning of the current day” mean? 8am? Browser time or Gateway time?

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [April 7, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/5 "2022-04-07T16:26:07Z")

</div>

As in starting from 00:00:00 of the date when the application has been opened

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 7, 2022, 4:26pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/6 "2022-04-07T16:26:35Z")

</div>

I am no python export but a startup script like this should do.

```auto
	from datetime import date
	self.props.value = date.today()

```

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [April 7, 2022, 4:28pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/7 "2022-04-07T16:28:05Z")

</div>

Thank you, but how can i link this to either my component or even a custom session property?

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [April 7, 2022, 4:28pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/8 "2022-04-07T16:28:25Z")

</div>

Right-click your DateTime component.  
Select “Configure Events”.  
Select the onStartup option under System Events.  
Select a Script Action.  
Supply the following script:

```auto
    from datetime import date
	from datetime import datetime
	today = date.today()
	midnight = datetime.combine(today, datetime.min.time())
	self.props.value = midnight

```

---

<div class="post-metadata">

**Author:** ![Dean\_Walsh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Dean\_Walsh](https://forum.inductiveautomation.com/u/Dean_Walsh)\
**Post date:** [April 7, 2022, 4:30pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/9 "2022-04-07T16:30:26Z")

</div>

> [@cmallonee](#):
>
> ```auto
> from datetime import date
> from datetime import datetime
> today = date.today()
> midnight = datetime.combine(today, datetime.min.time())
> self.props.value = midnight
> 
> ```

Oh thank you so much sir that is exactly what i was looking for

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 7, 2022, 4:32pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/10 "2022-04-07T16:32:17Z")

</div>

This is clearly my lack of knowledge, but what is the difference, something with time zones?  
My code sets the value to today 12AM, but your version is today 5AM, i know i am missing something simple.

---

<div class="post-metadata">

**Author:** ![ayu](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ayu/32/16635_2.png) [@ayu](https://forum.inductiveautomation.com/u/ayu)\
**Post date:** [April 7, 2022, 4:58pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/11 "2022-04-07T16:58:50Z")

</div>

Hi @josborn,

Seems likely it’s related to time zones. What is the time zone your session is running on and what time zone are you physically in? Any code snippets would be helpful as well.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 7, 2022, 5:00pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/12 "2022-04-07T17:00:00Z")

</div>

Everything should be in PST (GMT -8)

This is the code i placed on the component startup.

```auto
from datetime import date
self.props.value = date.today()

```

And the code that produced a time of 5AM was @cmallonee’s posted above.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [April 7, 2022, 5:15pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/13 "2022-04-07T17:15:08Z")

</div>

For your future sanity, use `system.date` functions instead of Jython’s somewhat-janky implementation of `date` and `datetime`:  
`self.props.value = system.date.midnight(system.date.now())`

The time discrepancy is probably because your script is executing _on the gateway_, which might have a different time zone than wherever you’re running your code.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 7, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/14 "2022-04-07T17:18:11Z")

</div>

Good to know, but everything is in PST time at least to my knowledge. Physically everything is here on campus.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [April 7, 2022, 8:04pm UTC](https://forum.inductiveautomation.com/t/default-value-for-datetime-picker/58177/15 "2022-04-07T20:04:27Z")

</div>

Ah, the on startup was not happening for some reason, this works perfectly.

> [@paul-griffith](#):
>
> system.date.midnight(system.date.now())
