Time fuction

how to extract current time of the system and write it to the tag which is defined as date??

i am able to extract time in string format but i want it in date format.because i want it to update it in mySQL table datetime column…

if you are doing this in a script (based on your other posts, I believe this to be true), then a datetime.datetime type will work.

[code]import datetime

#get current time
t=datetime.datetime.now()

#write to tag
system.tag.write("[default]Test/DateTime", t)[/code]

I find the java objects that exist under the hood are a bit easier to use. Jordan’s code would become:[code]from java.util import Date

#get current time
t=Date()

#write to tag
system.tag.write("[default]Test/DateTime", t)[/code]If you inspect any datetimes that come from component properties, you’ll find that they are instances of java.util.Date.

thanks for reply,

is there any way to perform arithmatic operation on this date i got…( i have performed arithmatic in expression binding but not sure same will work in component scripting or not.)

i wanted to add 90 mins to the time i stored in Tag …

system.date.add* performs arithmetic docs.inductiveautomation.com/pa … Id=6045659

tplus90 = system.date.addMinutes(t, 90)

i am using the code mentioned by pturmel:
from java.util import Date

#get current time
t=Date()

#write to tag
system.tag.write("[default]Test/DateTime", t)

but when i perform system.date.addMinutes(t,90) operation, i get following error:

1st arg can’t be coerced to java.util.Date…

is there any other way to perform date operation?

What is the exact code you are using? That should work fine, I just tested it and it works.

[code]from java.util import Date

#get current time
t=Date()

tplus90 = system.date.addMinutes(t, 90)
#write to tag
system.tag.write(“Test/DateTime”, tplus90)[/code]

thanks for the reply, it worked for system.date.now()…

i am using following code:

temp = 2
currentdate = system.date.now()
EntryGateTimeOut = system.date.addMinutes(currentdate, 90)
EntryTimeOut = system.date.format(EntryGateTimeOut,"YYYY-MM-dd HH:mm:SS")
system.tag.write("TT/TT%d/EntryGateTimeOutTime"%(temp),EntryTimeOut)