Day counter

Hello,

i want to built a counter for days. Example: every 15 days i want to display a message on a power panel. Exists for this appication a special fub ?

Hello,
you can use the Fuctionblock ā€œDTGetTimeā€ from theLibrary ā€œAsTimeā€.
It provides a output in the DATE_AND_TIME Format. Which is the Seconds since 1.1.1970.

If you display your message you can save the current Time and then add 15 * 24 * 60 = 21600 s to the value. The new Value can be used to check for the next event after 15 Days.

Greetings
Michael

1 Like

Hi,

this can be achieved with the Datatype ā€œDATE_AND_TIMEā€ and the library AsTime

Example:

Variables:

VAR
	lastTime : DATE_AND_TIME;
END_VAR
(**)
VAR
	FB_GetTime : DTGetTime;
END_VAR

Code:

	FB_GetTime(enable := TRUE);
	
	IF (FB_GetTime.status = ERR_OK AND DiffDT(FB_GetTime.DT1, lastTime) >= TIME_TO_UDINT(T#15d)) THEN
		lastTime := FB_GetTime.DT1;
		
		// Do your thing here
	END_IF

this will trigger immediately (since the timestamp in lastTime will be initialized with 0) and then every 15 days

You can have a look at the library and explore the other possibilities here

BR

4 Likes

Thanks to everyone! Itā€™s working