OK, what’s the nature of the date? Is it in an Item, hard coded, etc?
Try installing Date and Time which needs to be separately installed from Settings → Automation. That will
Errors in the logs? That should have worked. Looking at the code it generates a ZonedDateTime with that date and midnight as the time.
var dtf = Java.type("java.time.format.DateTimeFormatter");
var zdt = Java.type("java.time.ZonedDateTime");
function getZonedDateTime (datetime) {
return zdt.parse(datetime + ' 00:00:00 +00:00', dtf.ofPattern('yyyy-MM-dd HH:mm:ss z'))
}
var persistence = Java.type('org.openhab.core.persistence.extensions.PersistenceExtensions');
persistence.averageSince(itemRegistry.getItem('MyItem'), getZonedDateTime('2022-03-14'));
Install the Date and Time library and use those in place of the now
block. That will give you more flexibility if you need it.