# Writing dayOfWeek to tag

**URL:** <https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398>\
**Category:** Ignition\
**Created:** [March 21, 2023, 5:25pm UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398 "2023-03-21T17:25:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [March 21, 2023, 5:25pm UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398/1 "2023-03-21T17:25:28Z")

</div>

What is the best way to use getDayOfWeek so I have a tag that shows the current value 1-7? So far this is what i have gathered but cant seem to piece it all together.....

> date = system.date.now()  
> print system.date.getDayOfWeek(date)  
> system.tag.writeBlocking("Tag Path to write to",[date])

Thank you.

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [March 21, 2023, 5:32pm UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398/2 "2023-03-21T17:32:54Z")

</div>

If I'm reading what you want right, then your just missing storing your day of week to a variable and using that for your write function. If that's right, then you just need something like:

```auto
date = system.date.now()
day = system.date.getDayOfWeek(date)
system.tag.writeBlocking("Tag Path to write to",[day])

```

But if your just putting it in a tag I'd just do an expression tag and use:

```auto
getDayOfWeek(now())

```

---

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [March 21, 2023, 6:09pm UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398/3 "2023-03-21T18:09:47Z")

</div>

You got it. Thank you I really appreciate the help.

---

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [March 23, 2023, 11:59am UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398/4 "2023-03-23T11:59:36Z")

</div>

Can anyone tell me why this script changes the value of my tag like i want it to if i run it in script console but doesnt do anything when i set it to a gateway timer at 5000ms or a scheduled gateway event that runs every minute?

```auto
CurrentDay = system.tag.read('Tag Path').value
CurrentFlow = system.tag.read('[Tag Path').value
	
if CurrentDay == 5 and CurrentFlow < 100:
	system.tag.write('Tag Path', 40)
if CurrentDay == 7 and CurrentFlow < 100:
	system.tag.write('Tag Path', 40)
if CurrentDay == 5 and CurrentFlow > 100:
	system.tag.write('Tag Path', 60)
if CurrentDay == 7 and CurrentFlow > 100:
	system.tag.write('Tag Path', 60)

```

Obviously where it says Tag Path I have the correct path in it.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [March 23, 2023, 12:15pm UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398/5 "2023-03-23T12:15:18Z")

</div>

Well for one is that the time zone of your gateway is in the .conf file, and the timezone that your script console is running in is set to the timezone of the computer you opened designer on, so while unlikely I guess it's feasible that your designer could have been on day 5/7 but the gateway was one 6 or 1.

Another thing is after making the gateway event - if Gateway Events it is still italicized in the object explorer, it is not running your new script. You have to save your project.

I agree with @bpreston here though, even this script I think can be done with a expression case statement.

---

<div class="post-metadata">

**Author:** ![kaleb.s](https://avatars.discourse-cdn.com/v4/letter/k/f08c70/32.png) [@kaleb.s](https://forum.inductiveautomation.com/u/kaleb.s)\
**Post date:** [March 23, 2023, 12:52pm UTC](https://forum.inductiveautomation.com/t/writing-dayofweek-to-tag/71398/6 "2023-03-23T12:52:05Z")

</div>

Gateway time zone is accurate and is the same as my PC. I added to the script to write no matter what day 1-7 and still didnt. The script is running and it is not italicized.....

I figured it out. All good.
