Question on scripting to DateTime Input

I am trying to push +1 hour into my datetime picker using a button but having great difficulty, i know this component has its own functionality for that but my boss requested this.
The problem I’m having is getting the value of the datetime picker inside my script, so I can manipulate it based on whichever datetime is selected on it.
this is my code.

	import datetime as DT
	from datetime import date
	from datetime import datetime
	
	self.session.custom.hour = self.session.custom.hour + 1
	current = self.getSibling("DateTimeInput").props.value #datetime.now()
	minushour = current - DT.timedelta(hours= self.session.custom.hour)
	
	self.getSibling("DateTimeInput").props.value = minushour
	

you’ll noticed the hashed out datetime.now(), if I have this alone as the value of ‘current’ the script runs fine but the problem being it will set the datetime picker to the current time minus whatever hour, instead of keeping the selected datetime and minusing one hour from that value. (i hope i explained that coherently)
the error i get is this
image
I believe this is saying I cannot use any timedelta script onto my datetime picker components value because it isn’t a properly formatted datetime like datetime.now() is

If anybody could help me with this or confirm that it is impossible I would appreciate it.

Why not use the system.date.* functions?

current = self.getSibling("DateTimeInput").props.value
self.getSibling("DateTimeInput)".props.value = system.date.addHours(current,self.suession.custom.hour + 1)
1 Like

Thank you, I did not realise this function existed

I have Ignition's system function appendix bookmarked in my browser. Very handy when you need to look for something you haven't used before or didn't know existed. The appendix for expressions is very helpful too

image

3 Likes

Oh thank you, I have now done the same that is extremely helpful. Thanks guys

1 Like

Tip: Whenever you start importing from python’s stdlib in jython, stop. Check if there is an Ignition system. function that meets your need, or a java stdlib class that meets your need. jython’s stdlib is a last resort.

3 Likes