# Time fuction

**URL:** <https://forum.inductiveautomation.com/t/time-fuction/12373>\
**Category:** Ignition\
**Created:** [November 17, 2016, 12:39pm UTC](https://forum.inductiveautomation.com/t/time-fuction/12373 "2016-11-17T12:39:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 17, 2016, 12:39pm UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/1 "2016-11-17T12:39:02Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 17, 2016, 1:31pm UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/2 "2016-11-17T13:31:07Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 17, 2016, 2:12pm UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/3 "2016-11-17T14:12:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 20, 2016, 10:39am UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/4 "2016-11-20T10:39:39Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [November 21, 2016, 7:42am UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/5 "2016-11-21T07:42:56Z")

</div>

system.date.add\* performs arithmetic [docs.inductiveautomation.com/pa … Id=6045659](https://docs.inductiveautomation.com/pages/viewpage.action?pageId=6045659)

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

---

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 21, 2016, 11:09am UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/6 "2016-11-21T11:09:15Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![accyroy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/accyroy/32/3386_2.png) [@accyroy](https://forum.inductiveautomation.com/u/accyroy)\
**Post date:** [November 21, 2016, 12:18pm UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/7 "2016-11-21T12:18:12Z")

</div>

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]

---

<div class="post-metadata">

**Author:** ![roshanbhosale](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/roshanbhosale/32/4899_2.png) [@roshanbhosale](https://forum.inductiveautomation.com/u/roshanbhosale)\
**Post date:** [November 22, 2016, 9:14am UTC](https://forum.inductiveautomation.com/t/time-fuction/12373/8 "2016-11-22T09:14:12Z")

</div>

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

i am using following code:

```auto
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)
```
