FUNCTION_BLOCK Epoch_Time
RTC_READ_1(RTC_READ_ENABLED);
CASE RTC_READ_1.RTCData.Month OF
	1: prev_months_days := 0;
	2: prev_months_days := 31;
	3: prev_months_days := 59;
	4: prev_months_days := 90;
	5: prev_months_days := 121;
	6: prev_months_days := 151;
	7: prev_months_days := 181;
	8: prev_months_days := 212;
	9: prev_months_days := 243;
	10: prev_months_days := 273;
	11: prev_months_days := 304;
	12: prev_months_days := 334;
END_CASE;

IF MOD(ANY_TO_DINT(RTC_READ_1.RTCData.Year), 4) = 0 THEN
	IF RTC_READ_1.RTCData.Month > 2 THEN
		prev_months_days := prev_months_days + 1;
	END_IF;
END_IF;

year_seconds := ANY_TO_ULINT(RTC_READ_1.RTCData.Year - ANY_TO_UINT(1970)) * ANY_TO_ULINT(31556926);
day_seconds := ANY_TO_ULINT((prev_months_days + RTC_READ_1.RTCData.Day) * ANY_TO_UINT(86400));
hour_seconds := ANY_TO_ULINT(RTC_READ_1.RTCData.Hours * 3600);
min_seconds := ANY_TO_ULINT(RTC_READ_1.RTCData.Minutes * 60);

Epoch := year_seconds + day_seconds + hour_Seconds + ANY_TO_ULINT(RTC_READ_1.RTCData.Seconds);
END_FUNCTION_BLOCK