# dateExtract not defined?

**URL:** <https://forum.inductiveautomation.com/t/dateextract-not-defined/9499>\
**Category:** Ignition\
**Created:** [December 31, 2014, 1:23pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499 "2014-12-31T13:23:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colerick](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Colerick](https://forum.inductiveautomation.com/u/Colerick)\
**Post date:** [December 31, 2014, 1:23pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499/1 "2014-12-31T13:23:17Z")

</div>

Morning,

Attempting to use the dateExtract function in the Script playground,  
receiving the below error. I am not a Java expert…

Suggestions?

Thanks,

Andy

Traceback (most recent call last):  
File “”, line 6, in   
NameError: name ‘dateExtract’ is not defined

```
at org.python.core.Py.NameError(Py.java:260)
at org.python.core.PyFrame.getname(PyFrame.java:257)
at org.python.pycode._pyx21.f$0(<script playground>:6)
at org.python.pycode._pyx21.call_function(<script playground>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:568)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:557)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:551)
at com.inductiveautomation.ignition.designer.gui.tools.ScriptPlayground.runScript(ScriptPlayground.java:210)
at com.inductiveautomation.ignition.designer.gui.tools.ScriptPlayground$2.actionPerformed(ScriptPlayground.java:226)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

```

Ignition v7.7.1 (b2014092209)  
Java: Oracle Corporation 1.8.0\_25

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [December 31, 2014, 2:31pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499/2 "2014-12-31T14:31:01Z")

</div>

dateExtract is an [expression function](https://support.inductiveautomation.com/usermanuals/ignition/expressions_overview.htm) not a scripting function so it can not be used in the script playground.

Expression and scripting functions are not a part of the Java language.

If you provide some more details about what you are trying to do I’m sure someone here can get help get you started.

---

<div class="post-metadata">

**Author:** ![Colerick](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Colerick](https://forum.inductiveautomation.com/u/Colerick)\
**Post date:** [December 31, 2014, 3:04pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499/3 "2014-12-31T15:04:17Z")

</div>

Thanks for the explanation.

Looking to sync time of multiple Opto22 SNAP-PAC controllers with gateway pc.

I’d like to write current time broken out to year, month, day, etc. to a data type including a trigger bit,  
then update Opto controllers time.

I thought I’d do this with a script on a button press.

Thanks

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://forum.inductiveautomation.com/u/Pat)\
**Post date:** [December 31, 2014, 5:32pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499/4 "2014-12-31T17:32:19Z")

</div>

If you want to do it from a button you could use a Python script like this -

[code]#get time from database  
dbTime = system.db.runQuery("SELECT HOUR(NOW()) as hours, " +  
"MINUTE(NOW()) as minutes, " +  
“SECOND(NOW()) as seconds”)

tags = [“MasterClock/SCADA/Hours”, “MasterClock/SCADA/Minutes”,  
“MasterClock/SCADA/Seconds”, “MasterClock/SCADA/SyncClocks”]  
values = [dbTime[0][“hours”], dbTime[0][“minutes”],  
dbTime[0][“seconds”]+1, 1]

#write time to Master Clock PLC and set SyncClocks bit  
system.tag.writeAll(tags, values)[/code]

I use a gateway script that updates the clock every morning -

[code]from time import localtime, strftime  
curTime = strftime("%H:%M:%S", localtime())

if curTime == “00:00:01”:  
#sync PLC clocks to server’s time  
system.tag.write(“MasterClock/SCADA/Hours”, 0)  
system.tag.write(“MasterClock/SCADA/Minutes”, 0)  
system.tag.write(“MasterClock/SCADA/Seconds”, 1)  
system.tag.write(“MasterClock/SCADA/SyncClocks”, 1)[/code]

---

<div class="post-metadata">

**Author:** ![Colerick](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@Colerick](https://forum.inductiveautomation.com/u/Colerick)\
**Post date:** [December 31, 2014, 6:08pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499/5 "2014-12-31T18:08:26Z")

</div>

Thanks, that looks promising.

Andy

---

<div class="post-metadata">

**Author:** ![Duffanator](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/duffanator/32/3560_2.png) [@Duffanator](https://forum.inductiveautomation.com/u/Duffanator)\
**Post date:** [January 5, 2015, 2:08pm UTC](https://forum.inductiveautomation.com/t/dateextract-not-defined/9499/6 "2015-01-05T14:08:44Z")

</div>

You can use this stand alone application from Opto 22 to time sync all of your controllers. I have this running on my Ignition server to do just that. Nothing fancy but it works great.

[Uio Time R1.3 Distribution.zip](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e7fa5ff6ab6e3cd768eb0dc8f72c40cc054bd69f.zip) (105 KB)
