Time-Of-Day Functions
Time-Of-Day Functions
S7-1500) 1
Manual
V20
11/2024
Legal information
Warning notice system
This manual contains notices you have to observe in order to ensure your personal safety, as
well as to prevent damage to property. The notices referring to your personal safety are
highlighted in the manual by a safety alert symbol, notices referring only to property damage
have no safety alert symbol. These notices shown below are graded according to the degree of
danger.
DANGER
indicates that death or severe personal injury will result if proper precautions are not taken.
WARNING
indicates that death or severe personal injury may result if proper precautions are not taken.
CAUTION
indicates that minor personal injury can result if proper precautions are not taken.
NOTICE
indicates that property damage can result if proper precautions are not taken.
If more than one degree of danger is present, the warning notice representing the highest
degree of danger will be used. A notice warning of injury to persons with a safety alert symbol
may also include a warning relating to property damage.
Qualified Personnel
WARNING
Siemens products may only be used for the applications described in the catalog and in the
relevant technical documentation. If products and components from other manufacturers are
used, these must be recommended or approved by Siemens. Proper transport, storage,
installation, assembly, commissioning, operation and maintenance are required to ensure
that the products operate safely and without any problems. The permissible ambient
2 Manual, 11/2024
conditions must be complied with. The information in the relevant documentation must be
observed.
Trademarks
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and
software described. Since variance cannot be precluded entirely, we cannot guarantee full
consistency. However, the information in this publication is reviewed regularly and any
necessary corrections are included in subsequent editions.
Siemens Aktiengesellschaft
Copyright © Siemens 2024.
Digital Industries
11/2024 Subject to change All rights reserved
Postfach 48 48
90026 NÜRNBERG
GERMANY
Manual, 11/2024 3
Table of content
4 Manual, 11/2024
Manual, 11/2024 5
Time-of-day functions (S7-1200, S7-1500)
You can query whether errors have occurred during execution of the instruction in the RET_VAL
output parameter.
The "WR_SYS_T" instruction is not used to pass information about the local time zone or daylight
saving time.
Note
Module time of CPU clock
The CPU clock interprets the module time as the coordinated universal time (UTC).
Accordingly, the module time is always stored without the factors "local time zone"
or "summer time" in the CPU clock. The CPU clock then calculates the local time of
the CPU clock based on the module time.
The module time of the CPU clock is used as template for all time processes
starting from the CPU. Examples of use:
Representation of the module time in local time under "Online & Diagnostics"
Block properties
Parameter
The following table shows the parameters of the "WR_SYS_T" instruction:
S7-1200 S7-1500
6 Manual, 11/2024
IN Input DTL DT **, DTL, I, Q, M, D, L, P or Date and time
LDT constant *
* The data types DT and DTL are not used for the following memory areas: input, output
and bit memory.
** When using the data type DT the milliseconds are not transferred to the CPU.
You can find additional information on valid data types under "Overview of the valid data types".
Parameter RET_VAL
Error Description
code*
(W#16#....)
0000 No error
8082** Invalid value specified for the month (byte 2 in DTL format).
8083** Invalid value specified for the day (byte 3 in DTL format).
8084** Invalid value specified for the hour (byte 5 in DTL format).
8085** Invalid value specified for the minute (byte 6 in DTL format).
8086** Invalid value specified for the second (byte 7 in DTL format).
8087** Invalid value specified for the nanosecond (bytes 8 to 11 in DTL format).
* The error codes can be displayed as integer or hexadecimal values in the program
editor. For information on switching the display formats, refer to "See also".
** Only if the date and time are specified at the parameter IN in DTL format
Example
Manual, 11/2024 7
Create three tags in a global data block for storing the data.
Interconnect the parameters of the instruction as follows. Select the DATE AND TIME data type.
If the normally open contact ("execute") supplies the signal state "TRUE", the "WR_SYS_T"
instruction is executed. The module time of the CPU clock is overwritten with the time to be set
("inputTIME"). The output parameter RET_VAL ("returnValueT") indicates that processing took
place without errors.
You can establish whether the new module time ("inputTIME") has been correctly received by
the CPU clock as follows:
Using the display of an S7-1500 CPU: Navigate on the CPU display to "Settings > Date &
Using TIA Portal: Read out the module time of the CPU clock using the "RD_SYS_T"
instruction.
Using TIA Portal: Navigate to the "Online & Diagnostics" entry of the CPU, and open the
The Coordinated Universal Time (UTC) is set for the module time of the CPU clock. Central
European Time is set as local time in the TIA Portal in this example. Accordingly, an hour is
added to the time to be set ("inputTIME") in the "Online & Diagnostics" entry in the TIA
8 Manual, 11/2024
Portal. Another hour is added when daylight saving time is used. The calculated local time is
See also
Switching display formats in the program status
Sample Library for Instructions (S7-1200, S7-1500)
Description
You use this instruction to read the current date and current time-of-day (module time) of the
CPU clock.
The read dates are output at the OUT output parameter of the instruction. The provided value
does not include information about the local time zone or daylight saving time.
Note
Module time of CPU clock
The CPU clock interprets the module time as the coordinated universal time (UTC).
Accordingly, the module time is always stored without the factors "local time zone"
or "summer time" in the CPU clock. The CPU clock then calculates the local time of
the CPU clock based on the module time.
The module time of the CPU clock is used as template for all time processes
starting from the CPU. Examples of use:
Representation of the module time in local time under "Online & Diagnostics"
Block properties
You can query whether errors have occurred during execution of the instruction in the
RET_VALoutput.
Parameters
The following table shows the parameters of the "RD_SYS_T" instruction:
Manual, 11/2024 9
RET_VAL Return INT INT I, Q, M, D, L, P Status of the
instruction
* The data types DT and DTL cannot be used for the memory areas: input, output and bit
memory.
You can find additional information on valid data types under "Overview of the valid data types".
Parameter RET_VAL
Error Description
code*
(W#16#....)
0000 No error
8081 The data read out cannot be saved because it is outside the permissible
range for the selected data type of OUT parameter.
11-[Link].854775807
[Link].854775807
* The error codes can be displayed as integer or hexadecimal values in the program
editor. For information on switching the display formats, refer to "See also".
Example
In the following example, you read out the module time of the CPU clock. The data type used is
DATE AND TIME.
Create two tags in a global data block for storing the data.
Interconnect the parameters of the instruction as follows. Select the DATE AND TIME data type.
10 Manual, 11/2024
The module time of the CPU clock is read out and displayed at output parameter OUT
("outputTIME"). The output parameter RET_VAL ("returnValue") indicates that processing took
place without errors.
See also
Switching display formats in the program status
Sample Library for Instructions (S7-1200, S7-1500)
Description
You use this instruction to read the current local time from the CPU clock and output this at the
OUT output. Information on the time zone and the start of daylight saving time and standard
time, which you have set in the configuration of the CPU clock, is used to output the local time.
Parameters
The following table shows the parameters of the "RD_LOC_T" instruction:
S7-1200 S7-1500
Manual, 11/2024 11
OUT Output DTL DT, LDT, DTL I, Q, M, D, L, P * Local time
* The data types DT and DTL cannot be used for the memory areas: input, output and bit
memory.
You can find additional information on valid data types under "Overview of the valid data types".
Parameter RET_VAL
Error Description
code*
(W#16#....)
0000 No error
8081 The current local time cannot be saved because it is outside the
permissible range for the selected data type of OUT parameter.
11-[Link].854775807
[Link].854775807
* The error codes can be displayed as integer or hexadecimal values in the program
editor. For information on switching the display formats, refer to "See also".
Example
In the following example, you read out the local time of the CPU clock. The data type used is
DATE AND TIME.
Create two tags in a global data block for storing the data.
Interconnect the parameters of the instruction as follows. Select the DATE AND TIME data type.
12 Manual, 11/2024
The local time of the CPU clock is read out and displayed at output parameter OUT
("outputLocTIME"). Output parameter RET_VAL ("returnValue") indicates that processing took
place without errors and the local time is output as daylight saving time with this call.
See also
Switching display formats in the program status
Sample Library for Instructions (S7-1200, S7-1500)
Description
The instruction "WR_LOC_T" is used to set the date and time of the CPU clock. Enter the date and
time-of-day as local time at the input parameter LOCTIME.
The value must be in the following range:
The granularity of the time information for local time and system time is product-specific and is
at least one millisecond. Input values at the LOCTIME parameter which are less than those
supported by the CPU are rounded up during system time calculation.
You can query whether errors have occurred during execution of the instruction in the RET_VAL
output parameter.
Parameters
The following table shows the parameters of the "WR_LOC_T" instruction:
Manual, 11/2024 13
LOCTIME Input DTL DTL, I, Q, M, D, L, P Local time
LDT or constant *
(second hour)
* The data type DTL cannot be used for the memory areas: input, output and bit
memory.
You can find additional information on valid data types under "Overview of the valid data types".
The clock is set back by (1) one hour at 3 a.m. This means there are two hours between
For all times for LOCTIME that are between [Link]0 AM and [Link]9
AM, you therefore need to declare whether the time is before or after the time changeover.
The DST parameter is used for this:
- With DST=TRUE, the time is in the first of the two hours, i.e. still in daylight saving time.
- With DST=FALSE, the time is in the second of the two hours, i.e. in standard time.
For all times for LOCTIME that are outside the double hour, DST is irrelevant.
The clock is set forward by (1) one hour at 2 a.m. This means there is no hour between
[Link]0 AM and [Link]9 AM.
If you specify a time within this hour at LOCTIME, the error code W#16#8089 is output.
14 Manual, 11/2024
(1)The description here assumes Central European Time (CET). The changeover time for CET is
2:00 AM (start of daylight saving), or 3:00 AM (end of daylight saving). Different changeover
times may apply correspondingly to other time zones.
Parameter RET_VAL
Error Description
code*
(W#16#....)
0000 No error.
8081 Time value specified at the LOCTIME parameter is outside the valid value
range:
[Link].999999999
[Link].999999999
8082** Invalid value specified for the month (byte 2 in DTL format).
8083** Invalid value specified for the day (byte 3 in DTL format).
8084** Invalid value specified for the hour (byte 5 in DTL format).
8085** Invalid value specified for the minute (byte 6 in format DTL).
8086** Invalid value specified for the second (byte 7 in DTL format).
8087** Invalid value specified for the nanosecond (byte 8 to 11 in DTL format).
8089 Time value does not exist (hour already passed upon changeover to
daylight saving time).
* The error codes can be displayed as integer or hexadecimal values in the program
editor. For information on switching the display formats, refer to "See also".
** Only for local time information at the LOCTIME parameter in DTL format.
Example
Manual, 11/2024 15
In the following example, you set the local time of the CPU clock. The data type used is DTL.
Create four tags in a global data block for storing the data.
Interconnect the parameters of the instruction as follows. Select the DTL data type.
If the normally open contact ("execute") supplies the signal state "TRUE", the "WR_LOC_T"
instruction is executed. The local time of the CPU clock is overwritten with the time to be set
("inputLocTIME"). The output parameter RET_VAL ("returnValue") indicates that the process took
place without errors. Input parameter DST ("dstValue") specifies that the time information refers
to standard time. This parameter is only relevant for the "double hour" (see description
"Parameter DST").
You can establish whether the new local time ("inputLocTIME") has been correctly received by
the CPU clock as follows:
Using the display of an S7-1500 CPU: Navigate on the CPU display to "Settings > Date &
16 Manual, 11/2024
Using TIA Portal: Read out the local time of the CPU clock using the "RD_LOC_T" instruction.
Using TIA Portal: Navigate to the "Online & Diagnostics" entry of the CPU, and open the
See also
Switching display formats in the program status
Sample Library for Instructions (S7-1200, S7-1500)
Description
Use the instruction "SET_TIMEZONE" to set the parameter for the local time zone and the
daylight saving / standard time changeover.
The settings which are carried out with the instruction "SET_TIMEZONE" correspond with the
settings for the time-of-day in the properties of the CPU. Define the corresponding parameters in
the system data type TimeTransformationRule for execution of the instruction "SET_TIMEZONE".
The local time is calculated based on the system time using the settings for the time zone and
the daylight saving / standard time changeover. The system time of the CPU is the UTC time. The
system time is used exclusively for communication within the system.
Note
Calling the "SET_TIMEZONE" instruction
The instruction "SET_TIMEZONE" writes data internally to the load memory of the
CPU. Accordingly, the change in time zone also applies after a power failure.
Calling the instruction again is unnecessary.
Call the instruction once every time the time zone has to be changed. For example,
it is advisable to call "SET_TIMEZONE" in a startup OB.
Note
Use with CPUs of the S7-1500 series
The "SET_TIMEZONE" instruction can only be used with a CPU of the S7-1500 series
starting from firmware version V1.7.
Parameters
The following table shows the parameters of the "SET_TIMEZONE" instruction:
Manual, 11/2024 17
Parameter Declaration Data type Memory Description
area
the function is
executed.
function is executed
on a positive edge of
REQ.
or still in progress
1: Job completed
without error
18 Manual, 11/2024
BUSY Output BOOL I, Q, Status parameter:
M,
D, L, 0: Job not yet started or already completed
P
1: Job not yet completed. A new job cannot be
started.
You can find additional information on valid data types under "Overview of the valid data types".
Parameter TimeZone
You store the parameters for the local time zone and the daylight saving/standard time
changeover in the TimeTransformationRule system data type
You create the TimeTransformationRule by entering TimeTransformationRule as the data type in
a data block or the local interface of a function block.
The structure of the TimeTransformationRule is as follows:
TimeTransformationRule STRUCT
Bias INT Time difference between the local time and the
system time (UTC) in minutes. The value must be
between -720 and +780 minutes (-12 to +13
hours).
The value (UTC -12 to +13 hours) corresponds to
the time zones that you specify in the properties
of the CPU.
Manual, 11/2024 19
"StandardStart..." are set to "0". Only the value of
parameter STATUS.
Specification of the time of day for changeover to daylight saving time. The following
times always refer to the local time.
Specification of the time of day for changeover to standard time. The following times
always refer to the local time.
20 Manual, 11/2024
...
12 = December
Parameter STATUS
Error Description
code*
(W#16#....)
7002 Intermediate call (REQ irrelevant): Instruction already active; BUSY has the
value "1".
8092 The "SET_TIMEZONE" instruction is not supported by your CPU type or this
firmware version of your CPU.
Manual, 11/2024 21
executed until at least one of the block calls is finished.
* The error codes can be displayed as integer or hexadecimal values in the program
editor. For information on switching the display formats, refer to "See also".
Example
Note
Validity of the example
The following example applies in this form only to S7-1500 with instruction version
< V2.0.
In the following example, you set the parameters for the local time zone and the daylight
saving/standard time changeover. You are advised to call the example in a startup OB.
Create the following for storing the data in a global data block: The "timezone" structure (with
the TimeTransformationRule data type) and five additional tags.
Note
If you want to call the example in a startup OB: Set the start value of the tag
"execute" to "TRUE".
Create a local tag for the interconnection of the output parameter DONE.
22 Manual, 11/2024
Network 1: Interconnect the parameters of the "SET_TIMEZONE" instruction as follows.
Network 3: After successful processing, have the input parameter REQ ("execute") automatically
reset as follows.
Network 4: To ensure that the instruction "SET_TIMEZONE" is fully processed when called in a
startup OB, use the instructions JMP (in network 4) and Label (see network 1).
Manual, 11/2024 23
Note
If you want to call the example in a startup OB, the CPU for processing the example
must be in startup. Set the CPU to STOP mode before you load the example to the
CPU. Then set the CPU to RUN mode.
If the input parameter REQ ("execute) returns the signal state "TRUE", the data for the time zone
of the CPU clock is overwritten by the data to be set ("timezone"). That also means that:
Output parameter BUSY ("modeBUSY") goes to signal state "TRUE". After processing, output
parameter BUSY shows the value "FALSE" and output parameter DONE ("#statDone") shows
the value "TRUE". The success status is saved to the "modeDONE" tag.
The output parameter STATUS ("statusTime") indicates how processing is running*. (*The job
processing begins (value "7001") and the instruction is then shown as already active (value
"7002").)
The output parameter ERROR ("modeERROR") indicates that processing is running without
errors (signal state is "FALSE").
24 Manual, 11/2024
Note: The "SET_TIMEZONE" instruction is level-triggered. The instruction is executed only when
the input parameter REQ ("execute") returns the signal state "TRUE".
After successful processing of SET_TIMEZONE ("modeDONE" is "TRUE"), the input parameter REQ
("execute") is automatically reset to the value "FALSE". The value "16#7002" is queried for
"statusTime" for this purpose. After the reset, the status value "16#7000" is output.
Manual, 11/2024 25
You can establish whether the data to be set ("timezone") has been correctly received by the
CPU clock as follows:
Using the display of an S7-1500 CPU: Navigate on the CPU display to "Settings > Date &
Time > Daylight Saving Time".
Using TIA Portal: Read out the local time of the CPU clock using the "RD_LOC_T" instruction.
Using TIA Portal: Read out the module time of the CPU clock using the "RD_SYS_T"
instruction.
See also
Sample Library for Instructions (S7-1200, S7-1500)
Description
26 Manual, 11/2024
You use this instruction to synchronize all slave clocks present locally on the CPU or locally on a
bus segment independent of the set synchronization interval (the external interface of a CP or
CM belongs to a different bus segment). Successful synchronization is only possible if
"SNC_RTCB" is called on a CPU whose real-time clock was assigned as the master clock for at
least one bus segment.
Parameters
The following table shows the parameters of the "SNC_RTCB" instruction:
You can find additional information on valid data types under "Overview of the valid data types".
Parameter RET_VAL
0001 The existing clock was not assigned the master clock function for any of
the bus segments.
* The error codes can be displayed as integer or hexadecimal values in the program
editor. For information on switching the display formats, refer to "See also".
See also
Switching display formats in the program status
Description
With the "TIME_TCK" instruction, you read a time counter which counts the ms in which the CPU
is in RUN. The time counter counts from 0 to max. 2147483647 ms. In the case of an overflow,
counting restarts from 0. The time scale and the accuracy amount to 1 ms. The time counter is
only influenced by the operating modes of the CPU. You can, for example, use it to measure the
Manual, 11/2024 27
duration of processes by differentiation of the results of two "TIME_TCK" calls. The instruction
does not provide any error information.
The following table provides an overview of how the time counter changes depending on the
operating modes of the CPU.
Parameters
The following table shows the parameters of the "TIME_TCK" instruction:
You can find additional information on valid data types under "Overview of the valid data types".
Example
In the following example, you read out the time counter. You specify the return value in the
TIME data type.
Create one tag for storing the data in a global data block.
28 Manual, 11/2024
The time counter is read out and displayed at the output parameter RET_VAL
("outputCPUtimer").
See also
Switching display formats in the program status
Sample Library for Instructions (S7-1200, S7-1500)
Description
You can use this instruction to set, start, stop, and read out a 32-bit operating hours counter of
your CPU.
Ensure that the operating hours counter can also be stopped or restarted during execution of
the user program, which may render the saved values incorrect.
Parameters
The following table shows the parameters of the "RTM" instruction:
Manual, 11/2024 29
highest value that can be displayed
2: stop
parameter PV
You can find additional information on valid data types under "Overview of the valid data types".
Parameter RET_VAL
0000 No error
30 Manual, 11/2024
General error information See also: Evaluating errors with GET_ERR_ID
Example
In the following example, you set the operating hours counter of the CPU and read out the value
after an hour.
Create six tags in a global data block for storing the data.
Interconnect the parameters of the instruction as follows. At input parameter NR, specify the
number of the operating hours counter of the CPU.
If the normally open contact ("execute") supplies the signal state "TRUE", the "RTM" instruction is
executed. The operating hours counter of the CPU is set to the value to be set
("in_processValue") and started. After the start of the operating hours counter, set the value of
input parameter MODE ("comandMODE") to "0". (To do so, click the parameter and select
"Modify operand > Set to 0".) As a result, the "RTM" instruction only reads the current value
("currentValue") of the operating hours counter without changing it. Output parameter CQ
("statusRTM") indicates after the start of the operating hours counter that the operating hours
counter is running (value is "TRUE"). The output parameter RET_VAL ("returnValue") indicates
that processing is running without errors.
Manual, 11/2024 31
After an hour, output parameter CV ("currentValue") indicates the value "6".
See also
Sample Library for Instructions (S7-1200, S7-1500)
32 Manual, 11/2024