# How to get datte and time in a event script (client/gateway)

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-datte-and-time-in-a-event-script-client-gateway/5315>\
**Category:** Ignition\
**Created:** [October 23, 2012, 8:47pm UTC](https://forum.inductiveautomation.com/t/how-to-get-datte-and-time-in-a-event-script-client-gateway/5315 "2012-10-23T20:47:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [October 23, 2012, 8:47pm UTC](https://forum.inductiveautomation.com/t/how-to-get-datte-and-time-in-a-event-script-client-gateway/5315/1 "2012-10-23T20:47:34Z")

</div>

Hello Everyone,  
Technical support has not been able to answer my question so maybe one of you will.  
I want to be able to run a gateway script base on a tag value change, the script would simply look at the current time off the system and base on a per-determine time would select a recipient to send an email to, I know its not something difficult to do but unfortunately the Ignitions Help does not Help.

Ignition Version: 7.2.11

IF TimeHR \< 9 then:  
Recipient=[“xxxxx1@ind.com”]  
Else  
Recipient=[“xxxxx1@ind.com”,“xxxx2@ind.com”]

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![tduryee](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@tduryee](https://forum.inductiveautomation.com/u/tduryee)\
**Post date:** [October 23, 2012, 9:25pm UTC](https://forum.inductiveautomation.com/t/how-to-get-datte-and-time-in-a-event-script-client-gateway/5315/2 "2012-10-23T21:25:03Z")

</div>

Try this:

```auto
from datetime import datetime
myTime=datetime.now()
if myTime.hour < 9:
	Recipient=["xxxxx1@ind.com"]
else:
	Recipient=["xxxxx1@ind.com","xxxx2@ind.com"]
```

---

<div class="post-metadata">

**Author:** ![dave.fogle](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@dave.fogle](https://forum.inductiveautomation.com/u/dave.fogle)\
**Post date:** [October 23, 2012, 10:05pm UTC](https://forum.inductiveautomation.com/t/how-to-get-datte-and-time-in-a-event-script-client-gateway/5315/3 "2012-10-23T22:05:20Z")

</div>

I don't think that the datetime module was available in 7.2. Is there a specific reason why you don't want to do the time comparison in an expression tag using the timeBetween() function and then read that tag in your script?

The reason that I'm proposing the tag option is because I believe the only other way to work with dates in scripting back in 7.2 is to import the Java Calendar and Date objects and use those. These objects are not difficult to use but they do add a bit of complexity to your script which may not actually be needed.

---

<div class="post-metadata">

**Author:** ![tduryee](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@tduryee](https://forum.inductiveautomation.com/u/tduryee)\
**Post date:** [October 23, 2012, 11:03pm UTC](https://forum.inductiveautomation.com/t/how-to-get-datte-and-time-in-a-event-script-client-gateway/5315/4 "2012-10-23T23:03:12Z")

</div>

Here’s the alternative using calendar.

```auto
from java.util import Calendar
now=Calendar.getInstance()
myHour=now.get(now.HOUR_OF_DAY)
if myHour < 9:
   Recipient=["xxxxx1@ind.com"]
else:
   Recipient=["xxxxx1@ind.com","xxxx2@ind.com"]
```

Or if you want to use an expression, you can do this:

```auto
if(dateExtract(now(),"hour")<9,'["xxxxx1@ind.com"]','["xxxxx1@ind.com","xxxx2@ind.com"]')
```
