PLC Real Time Clock - Daylight Saving |
![]() |
| Name | DaylightSaving |
| Basic Function |
DaylightSaving - a Lightweight Function Blocks (FB) to change the PLC Real Time Clock (RTC) forward and backward by 1 hour for daylight saving time (DST) according to rules set in MonthFwd / WeekNoFwd / HourFwd and MonthBack / WeekNoBack / HourBack. This FB will always treat Sunday for DST changes. This accounts for most of Europe and America's. DaylightSavingWithNTP - a similar FB but provides a local Daylight saving (DLS) Date & Time based on the RTC value and DST rules (same as DaylightSaving FB). Since more common use of NTP/SNTP time servers, please use the DaylightSavingWithNTP FB which supports RTC periodic update. This means that DayLightSavingWithNTP does not write to the RTC value, but provides a local DLS Date & Time output variables. Set the NTP server so that TimeZone is included as NTP writes to RTC as UTC/GMT+TimeZone adjustment value. For more information about daylight saving in selected country/timezone see... |
|
|
Syntax |
Use DaylightSavingWithNTP when using NTP servers to sync RTC periodically.
Original DaylightSaving FB.
|
|
| File Name |
DaylightSaving.cxf DaylightSavingWithNTP.cxf |
|
| Applicable models | CPU Unit | CP1L/H, CJ1/CS1 (V3 or above), all CJ2's |
| Software | CX-Programmer Version 5.0 or higher | |
| Conditions for usage | ||
| Function Description |
A Function Block (FB) to take account of Daylight Saving time according Month and ‘Week number in Month’ rules. The FB will move the PLC Real Time Clock on by 1 hour at hour 'HourFwd' on the Sunday set in MonthFwd/WeekNoFwd setting – to Summer Time clock setting. At hour 'HourBack' on the Sunday set in MonthBack/WeekNoBack the clock will be put back by 1 hour. If Month/Week/Hour rules apply in a different world timezones, then this FB can be used for southern hemisphere too. Notes: DaylightSavingWithNTP. The FB uses the PLC RTC to create a local Date & Time that is adjusted by DST rules. Timezone information is required when setting in NTP/SNTP settings pages within Ethernet unit configuration. DaylightSaving. The FB only uses the local PLC RTC and conditions set to adjust the RTC. Timezone information is not used/required. |
|
| Kind of FB definition |
Stores variables between executions. Use only one instance in a PLC application. |
|
| FB Precautions |
For correct operation, this FB should always be ‘Enabled’ (so detection is made correctly). It is also provided with two inputs that will allow manual increment and decrement of the RTC by 1 hour. As a minimum the FB must be running on the Sunday specified in MonthFwd/WeekNoFwd at 'HourFwd' and also on the Saturday from 23:59:59 to Sunday at hour 'HourBack' specified in MonthBack/WeekNoBack.
The RTC ‘Day of Week’ must be set correctly. (0=Sun, 6=Sat)
Test fully in own code to ensure correct operation. |
|
| EN input condition | Always On | |
- Variable Table
Input variables
| Name | Variable name | Data type | Default | Range | Description |
| EN |
P_On |
BOOL |
Always Enable (P_On) for correct operation. |
||
| MonthFwd |
|
UINT |
1-12 |
Month number (1 to 12) to put RTC forward by 1 hour |
|
| WeekNoFwd |
|
UINT |
1-4 |
Week number in MonthFwd to put on by 1 hour. Sunday is always used as the day of week to move clock forward. Week number can be 1 to 4. For last Sunday, set 0 |
|
| HourFwd |
|
UINT |
1-23 |
Hour number to move forward on specified Sunday |
|
| MonthBack |
|
UINT |
1-12 |
Month number (1 to 12) to put RTC backward by 1 hour |
|
| WeekNoBack |
|
UINT |
1-4 |
Week number in MonthBack to put back by 1 hour. Sunday is always used as the day of week to move clock backward. Week number can be 1 to 4. For last Sunday, set 0 |
|
| HourBack |
|
UINT |
1-23 |
Hour number to move backward on specified Sunday |
|
| IncHour |
Force1HrFwd |
BOOL |
Manual increment of RTC by 1 hour upon rising edge. HourForward flag is Set. |
||
| DecHour |
Force1HrBack |
BOOL |
Manual decrement of RTC by 1 hour upon rising edge. HourForward flag is Reset. |
Output variables (DaylightSavingWithNTP)
| Name | Variable name | Data type | Default | Range | Description |
| ENO |
ENO |
BOOL |
Unused |
||
| HourForward |
HourForward |
Retained During Power Off |
Flag to signify if in Daylight Saving mode (NB this flag is only set automatically at MonthFwd/WeekNoFwd and reset at MonthBack/WeekNoBack). Use Manual (IncHour/DecHour) to set initially. |
||
| LocalDT_mmss |
LocalDateTime_DLS[0] |
WORD (BCD) |
|
Local Date Time value with DLS applied. Mins:Secs as BCD |
|
| LocalDT_ddhh |
LocalDateTime_DLS[1] |
WORD (BCD) |
|
Local Date Time value with DLS applied. Day:Hour as BCD |
|
| LocalDT_yyMM |
LocalDateTime_DLS[2] |
WORD (BCD) |
|
Local Date Time value with DLS applied. Year:Month as BCD |
Output variables (DaylightSaving)
| Name | Variable name | Data type | Default | Range | Description |
| ENO |
ENO |
BOOL |
Unused |
||
| HourForward |
HourForward |
Retained During Power Off |
Flag to signify if in Daylight Saving mode (NB this flag is only set automatically at MonthFwd/WeekNoFwd and reset at MonthBack/WeekNoBack). Use Manual (IncHour/DecHour) to set initially. |
- Revision History
| Version | Date | Contents |
| 1.00 addition | 21 October 2025 | Addition of DaylightSavingWithNTP FB for use with NTP servers |
| 1.00 | 19 March 2012 | First release |





.jpg)
.jpg)

