# Checking date/time using python

**URL:** <https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349>\
**Category:** Ignition\
**Created:** [September 3, 2020, 12:13pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349 "2020-09-03T12:13:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![M\_W\_R](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@M\_W\_R](https://forum.inductiveautomation.com/u/M_W_R)\
**Post date:** [September 3, 2020, 12:13pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/1 "2020-09-03T12:13:53Z")

</div>

Hello,

I am new to python scripting and am wondering if anyone could with something I am trying to do. The goal is to write a value (1) to a tag on every monday at 8 AM and once this has happened once, to return the value back to a zero. I am trying to execute this using script running in the gateway. Is this possible to do?

---

<div class="post-metadata">

**Author:** ![pascal](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@pascal](https://forum.inductiveautomation.com/u/pascal)\
**Post date:** [September 3, 2020, 1:12pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/2 "2020-09-03T13:12:10Z")

</div>

Hi there.  
It is indeed possible.  
What you can do is create a boolean expression tag which will be used as a trigger becoming true every monday at 8 AM.  
Put this expression in your trigger boolean tag, you can call it trigger:

```auto
getDayOfWeek(now())=2&&getHour24(now())=8

```

Create a memory tag (you can call it target).  
Once the trigger becomes true, it will execute a Tag Change Gateway Event Script that will write value (1) in the target tag using this script :

```auto
system.tag.write("target",1)

```

This action will just set your target tag to 1, if you want to reet it to 0, you will have to use the invokeLater function in order to add a delay to your script :  
[https://docs.inductiveautomation.com/display/DOC79/Adding+a+Delay+to+a+Script](https://docs.inductiveautomation.com/display/DOC79/Adding+a+Delay+to+a+Script)

In this example, the script writes a value 1 in a tag and resets the value after 3 seconds :

````auto
def reset_tag():
    system.tag.write("target",0)

system.tag.write("target",1)
system.util.invokeLater(reset_tag, 3000)```
````

---

<div class="post-metadata">

**Author:** ![matthew.pless](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@matthew.pless](https://forum.inductiveautomation.com/u/matthew.pless)\
**Post date:** [September 3, 2020, 2:49pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/3 "2020-09-03T14:49:59Z")

</div>

If you are wanting to keep it in a Gateway Script you can try this approach. The only thing outside the gateway script is the tag itself. Just remember to change the wday to 0 for monday, and the hour to 8.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/6/161abfaefef4e9f80291de30cc0359c4e3a20370.png)

---

<div class="post-metadata">

**Author:** ![M\_W\_R](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@M\_W\_R](https://forum.inductiveautomation.com/u/M_W_R)\
**Post date:** [September 3, 2020, 6:20pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/4 "2020-09-03T18:20:41Z")

</div>

![Python_Error](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/2/a272f87645e515165bcd895ee275bddf3212e8a4.jpeg)

I keep getting this error when using the example script from above, not sure what I am doing wrong here? I appreciate the help though!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 3, 2020, 6:25pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/5 "2020-09-03T18:25:18Z")

</div>

You’re using the OPC item path while the function is expecting the TagPath.

Right click on the tag you want to write to in the Tag Browser of the designer, and select Copy Tag Path, then paste that in for the tag path in the system.tag.write function in your script.

The tag path is a string, so you will need to put it in quotes. Something like this:

```auto
system.tag.write('Your Tag Path Here')

```

---

<div class="post-metadata">

**Author:** ![M\_W\_R](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@M\_W\_R](https://forum.inductiveautomation.com/u/M_W_R)\
**Post date:** [September 9, 2020, 5:52pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/6 "2020-09-09T17:52:43Z")

</div>

![Ignition_Housing_h2O_Issue](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/8/e80fe26f31f3215189e0fc3b206904e5f59a498b.jpeg)

Thank you for all the help so far, I am still unable to get this to change values of the tag that I am trying to write to. In the picture I am trying to get this to change values today, wednesday at 12 noon (EST time over here) but I was unable to get this working. Is there anything I need to do to the tag that I have imported or the project for this to be successful?

---

<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:** [September 9, 2020, 6:03pm UTC](https://forum.inductiveautomation.com/t/checking-date-time-using-python/38349/7 "2020-09-09T18:03:25Z")

</div>

Don’t use python’s `time` module. Ignition is written in java, and its datetime objects are actually instances of `java.util.Date`. All of Ignition’s system.date.\* functions will give you this data type. Use them.
