Add DINT to STRING

I have an timestamp value, format STRING, for example: “2023-06-16T14:10:00Z”
Now i have also a DINT value containing seconds. (for example: 4000)
How can i add these seconds, to the timestamp value in STRING format in the IEC function blocks?

Hello!
What staff make you deal with such complicated way of timestamp operations? If You operate with date-time from plc itself, much more preferable will be next FC call
изображение.pngwhere you can eval number of significant second part by number of ‘f’ in strFormat variable/constant.
If you receive string timestamp from other source, as string variable, it became much more tricky because you have to parse and recombine it to proper LDT format, if you need do provide correct time sum/dec operations…
Can you please give a little bit wider explanation of your task?
Best regards

-- If he is adding seconds to a timestamp…I think he might be trying to build a time machine. – Are you sure your variable is a STRING and not an LDT? If it is a STRING, I think is correct…you will have to parse the string, convert a string to numerical, and concat the string back together.
If you really wanted to add 4000 seconds as you mention, that would be 1 hour, 6 minutes, 40 seconds.
You would use MID with Length = 2 and Starting Position = 18 to pull out your seconds (e.g., “00”). TO_INT the “00” to get 00. Add your 40 seconds (check to make sure your result is not 60…if so carry a minute). TO_STRING the result for a later CONCAT function.
You would use MID with Length = 2 and Starting Position = 15 to pull out your minutes (e.g., “10”). TO_INT the “10” to get 10. Add your 6 minutes (check to make sure your result is not 60…if so, carry an hour). TO_STRING the result for a later CONCAT function.
You would use MID with Length = 2 and Starting Position = 12 to pull out your hours (e.g., “14”). TO_INT the “14” to get 14. Add your 1 hour (check to make sure your result is <= 24). TO_STRING the result for a later CONCAT function.
Then CONCAT all your intermediate STRINGs back to your new STRING timestamp.
Ouch!
PS: If your time machine works, let me know. I want to try it out!
SFW

Hello!</p>What staff make you deal with such complicated way of timestamp operations? If You operate with date-time from plc itself, much more preferable will be next FC call </p>[https://forum.plcnext-community.net/uploads/WPFGG4KIX7NG/png.png</a></p>where you can eval number of significant second part by number of ‘f’ in strFormat variable/constant.</p>If you receive string timestamp from other source, as string variable, it became much more tricky because you have to parse and recombine it to proper LDT format, if you need do provide correct time sum/dec operations…</p>Can you please give a little bit wider explanation of your task?</p>Best regards</p>

It is true that it would be better to use the PLC’s date time format. However, I receive the timestamp from a third party in the format “2023-06-16T14:10:00Z”
I cannot compare this timestamp 1-to-1 with the PLC time because of the different formats. Now i also have the local PLC time in the same format using fb get_time so that I can easily compare both timestamps with a fb EQ.
I receive a timestamp for a certain command in combination with a value in seconds as long as this command has to be executed.
In the PLC I have to compare this received start time with the UTC time, then start the command during the received value in seconds.
I would therefore like to determine the “end time” of the assignment based on the start time and duration.

Code to convert string, formatted the way you noted (“2023-06-16T14:10:00Z”), can be easily implemented for converting to RTC_TYPE. Here is code sample
STR_TO_RTC.txtNext step is converting RTC to UNIX_timestamp
RTC_TO_UNIX_TIMESTAMP.txtThen, you can restore unix time to LDT with PBCL_DateTimeFromUnix (PLCNextBase libruary FB). And now can safely and freely provide any allowed operations with native time format. It seems that this is the best way to deal with it.
Best regards

STR_TO_RTC.txt
RTC_TO_UNIX_TIMESTAMP.txt

Also there is IEC 61131-3 Function CONCAT_LDT that provide RTC_TYPE conversion to LDATE_AND_TIME in native manner (vs RTC to UNIX_timestamp step).