I think it returns a HistoricState, which is strongly implied by the fact that you have to call max.state to get the value. If that’s the case than there is a getTimestamp() method which will give you the DateTime (I think a Joda DateTime, possibly just a java.util.Date) for the entry.
It’s been a very long time since I messed with these methods so my memory is rusty. I can’t answer which maximum entry get’s returned if there is more than one. I’d assume it’s the first one but it might depend on how the query is structured and end up being different from one database to the next.
btw is there any kind of list of the available properties on Items?
I’ve recently learned about .setLabel .getTmeStamp etc. but there will be many others for sure besides classic sendCommand, postUpdate etc.
If you use VSCode and install and properly configure the openHAB extension you can type an item name and “.” And a box will pop up showing all the methods and data members.
setLabel is not intended to be used from rules and doesn’t work reliably or as expected all of the time. Besides sendCommand, postUpdate, and the persistence methods (see https://www.openhab.org/docs/configuration/persistence.html#persistence-extensions-in-scripts-and-rules) the only useful methods on Items have to do with Groups: members, allMembers, getGroupNames, and add./removeGroup (or something like that to dynamically change group membership. I’m not where I can run VSCode myself right now so those method names need to be verified.