I have in Siemens TP270 output field "best before date" (yyyymmdd, DINT) and now i need to compare in plc (S7-400) that user can´t input date older or newer than 40 days. Any ideas how to do that
Do you mean that the operator has to enter the date in the format "yyyymmdd" ? I.e. 20110821 for 2011-08-21 ?
If that is the case, I think it would be less error prone if you have separate inputs for year, month and day.
And does it have to be eaxctly 40 days ? If you can accept approximately 40 days, it becomes easier as you dont have to account for 28-30-31 days per month.
In the Standard Library you'll find under "IEC Function Blocks" FC34 - SB_DT_DT which allows you to subtract one date and time from another - that should cover what you need.
Do you mean that the operator has to enter the date in the format "yyyymmdd" ? I.e. 20110821 for 2011-08-21 ?
If that is the case, I think it would be less error prone if you have separate inputs for year, month and day.
And does it have to be eaxctly 40 days ? If you can accept approximately 40 days, it becomes easier as you dont have to account for 28-30-31 days per month.
In the Standard Library you'll find under "IEC Function Blocks" FC34 - SB_DT_DT which allows you to subtract one date and time from another - that should cover what you need.
An idea.
First, check with FC34 if the difference output is greater than 24days. If yes, then subtract 24 days (FC35 SB_DT_TM), and again calculate the difference.
Then you can compare the difference with 16 days in stead of 40 days.
Not pretty but should work.
An idea.
First, check with FC34 if the difference output is greater than 24days. If yes, then subtract 24 days (FC35 SB_DT_TM), and again calculate the difference.
Then you can compare the difference with 16 days in stead of 40 days.
Not pretty but should work.
Just a hint.
When using time and dates on the S7 systems, try and use BCD values, not INTs.
Makes it easier to manipulate and reference.
The (S)FC's also expect BCD values.