Writing dayOfWeek to tag

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.

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:

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:

getDayOfWeek(now())
4 Likes

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

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?

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.

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.

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.