Default value for DateTime Picker

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.

Is this a vision or perspective question?

1 Like

perspective

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

1 Like

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

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

	from datetime import date
	self.props.value = date.today()
1 Like

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

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

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

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

1 Like

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.

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.

Everything should be in PST (GMT -8)

This is the code i placed on the component startup.

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

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

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.

1 Like

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

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

1 Like