Conversion of Time/Date to seconds

B97_TIME_DATE_TO_TOTAL_SECONDS

PROGRAM TEST_B97
   VAR
 SINT1,SINT2,SINT3,SINT4,SINT5,SINT7 :SINT;
  INT6:INT6;
  UDINT1: UDINT;  
    FB: LIB.CORE.V1_0.B97_TIME_DATE_TO_TOTAL_SECONDS;
   END_VAR
 FB(SEC:= SINT1, MIN:= SINT2,HOUR:=SINT3,DAY:=SINT4,MON:=SINT5,YEAR:=INT6,TOT=>UDINT1,WDAY=>SINT7);
END_PROGRAM

LIB\CORE

V1.0

The block converts time and date to total seconds (starting at 1.1.1970, 0:00). Another output is the current weekday.

InputTypeDescriptionDefault value
SEC SINTSeconds 0
MIN SINTMinutes 0
HOUR SINTHours 0
DAY SINTDays 0
MON SINTMonths 0
YEAR INT Years 0
OutputType Description
TOT UDINTNumber of seconds since 1.1.1970, 00:00 UTC
WDAY SINT Weekday (0 = Sun, 1 = Mon, …, 6 = Sat)

The block converts time and date to total seconds (starting at 1.1.1970, 0:00). Another integer output, wday, defines the current day of week (0 = Sunday, 1 = Monday, …, 6 = Saturday). For example, 1.1.1970 01:00 – one hour after the reference time start (i.e. sec=0, min=0, hour=1, day=1, mon=1, year=1970) - the outputs are tot=3600, and wday=4.


The block, together with B98, is used as an auxiliary block for various time/date conversions, calculating of time spans etc.

  • © Energocentrum Plus, s.r.o. 2017 - 2024