Perspective date time input - Can you add an option for current datetime?

I have a Perspective date time input with an onStartup script to give it the current datetime.

Would also like to have it zero the seconds if it can.

def runAction(self):
	from datetime import date
	self.props.value = system.date.now()

But manly I'd like the option to simply set it to the current datetime after the operator has set it to a few different dates.

Something like the "Today" option on the old MS Office DateTime Picker.
image

There is no need to import datetime

If you want a date to have zero seconds that can be accomplished.

self.props.value = system.date.setTime(system.date.now(),hour,minutes,seconds)

The other is not a terrible Idea, you should create an Ideas post.

1 Like

This seems to work:

def runAction(self):
	date = system.date.now()
	self.props.value = system.date.setTime(system.date.now(),system.date.getHour24(date),system.date.getMinute(date),0)

An expression binding of now(0) will run once on startup so you can use this in any of the date/time inputs to set the date. e.g.,

midnight(now(0))

For your application you want something like,

setTime(
	now(0), 
	getHour24(now(0)), 
	getMinute(now(0)), 
	0
)

https://docs.inductiveautomation.com/display/DOC81/Date+and+Time

1 Like