In 4D v12.1 the String command now accepts a third parameter, the addTime parameter. This can be used to add a time offset to a stringified date, for example when using an ISO date or Date RFC 1123.
One example of using this new parameter is to compare timestamps spanning across multiple days.
Let's say we have a table named [table1] with dates stored in [table1]date1 and times stored in [table1]time1 and you want to easily compare whether or not 1 hour has passed since the last time and date logged in the table.
Simply adding 1 hour to the value from the time field may not be good enough becuase if the previous time was after 11 PM (23:00) adding 1 hour to this value would not necessarily increase the value from the date field unless you specifically took it in to account in your programming logic.
However, this can easily be accomplished with the new functionality of the String command plus a simple comparisson.
C_TEXT($now;$lastPlus1hour) // get current timestamp $now:=String(Current date;ISO Date;Current time) // add 1 hour to last log entry $lastPlus1hour:=String([table1]date1;ISO Date;[table1]time1+?01:00:00?) If($now>$lastPlus1hour) // more than 1 hour has passed since last log entry // do something Else // less than 1 hour has passed since last log entry // do something else End if |
This works because when the ISO DATE format is used the string is output in the following format:
2010-09-13T23:11:53 |
Adding ?01:00:00? to the above time before using the String command would make the addTime value read 24:11:53 - when the String command reads this it interprets it correctly and increases the day value by one so the result reads like this:
2010-09-14T00:11:53 |