# What's wrong with this if statement

**URL:** <https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [September 10, 2024, 11:16pm UTC](https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822 "2024-09-10T23:16:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyle\_kelly](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@kyle\_kelly](https://forum.inductiveautomation.com/u/kyle_kelly)\
**Post date:** [September 10, 2024, 11:16pm UTC](https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822/1 "2024-09-10T23:16:09Z")

</div>

![Screenshot 2024-09-10 161239](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/c/dc0393f54f38692c027ddd7bb57efcef7efbff5f.png)

what's the correct syntax for:  
checking if the day of the week is 7 or more,  
setting the valve of a variable to 0 if it is more than 6,  
and adding 1 to that variable if it is 6 or less?

I know this code works without the 'if statement'.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [September 10, 2024, 11:31pm UTC](https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822/2 "2024-09-10T23:31:03Z")

</div>

2 things are wrong, your `if` statement syntax and your indentation. It may be worth your time to check out some intro to python videos or lessons to help get you started.

Additionally, there are system methods to pull the date, day of week, hour, etc from what is returned from `system.date.now()`.

Your script should look like:

```python
today = system.date.now()
DOW = system.date.getDayOfWeek(today)
hr = system.date.getHour24(today)
min = system.date.getMinute(today)
dowOffset = 0

if DOW > 6:
	dowOffset = 0
else:
	dowOffset = DOW + 1

system.tag.writeBlocking(
	["[Default]PC_Time_DOW","[Default]PC_Time_Hr", "[Default]PC_Time_Min"],[dowOffset, hr, min])

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 10, 2024, 11:43pm UTC](https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822/3 "2024-09-10T23:43:51Z")

</div>

Most specifically, it looks like you've mixed up the [expression language](https://www.docs.inductiveautomation.com/docs/8.1/platform/expression-language-and-syntax) and [Jython](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/python-scripting).

Also, I'm pretty sure your `dowOffset` conditional can be rewritten using the modulo operator.

---

<div class="post-metadata">

**Author:** ![kyle\_kelly](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@kyle\_kelly](https://forum.inductiveautomation.com/u/kyle_kelly)\
**Post date:** [September 10, 2024, 11:57pm UTC](https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822/4 "2024-09-10T23:57:23Z")

</div>

Thanks for the help, this solves my problem! I'll keep looking into the languages.

I'm still lost on when specific languages are needed. expect the addition part, (Dow\_Offset == Dow + 1) I have other 'if statements' on tags in this program that work using the format in the original post.

the "==" was part of me just trying everything i could think of.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 11, 2024, 7:27am UTC](https://forum.inductiveautomation.com/t/whats-wrong-with-this-if-statement/95822/5 "2024-09-11T07:27:52Z")

</div>

Here's an approximation:  
If it says 'script' somewhere on the window, it's jython, otherwise it's expressions.
