I'm just starting out with coding and I've been tasked with creating a timetable program that works between certain times. I've been given two approaches to achieve this, but I'm struggling with syntax and understanding how to implement them. For the first option, I'm comparing the current system date and time to some programmed start and end times. However, I'm getting compilation errors related to my IF statements, particularly when it comes to the END_IF.
In the current code, I set a variable called START to FALSE and then check if the system clock year is greater than or equal to the start year. I need to make sure I'm using the correct syntax for ending IF statements, and I'm confused about how to properly format this code.
The second option suggests converting my date and time variables to strings for easier comparisons, which sounds cleaner. I'm also not completely sure how to approach that either.
I'm looking for any advice on ending IF statements properly in my current code structure or suggestions on potentially better solutions for managing a timetable operation without getting bogged down by complicated string comparisons.
1 Answer
Hey! It sounds like you're using Structured Text for PLC programming. You definitely need an END_IF for every IF statement you open. Make sure your code is properly indented; it helps a lot in making it readable. Just format it like this:
```structured-text
IF (sysClock.year > %MW110.4) THEN
START := TRUE;
ELSE
IF (sysClock.year = %MW110.4) THEN
IF (sysClock.month > %MW110.3) THEN
START := TRUE;
ELSE ...
END_IF;
END_IF;
```
Don't forget that every ELSE statement also needs its own END_IF. Also, consider using built-in date/time functions that might be available with your PLC, as that could simplify comparisons significantly.

Thanks for the breakdown! I didn't realize I needed to clearly separate each condition like that. I'll definitely give it another go with proper indentation!