[SOLVED] Persistence: Request state to specific point in time (DateTime item)

Where DTT_time is oh DateTime (item with state).
and JDT_time is Joda Date Time
Right?

Thanks for the explanation (still confusing with the imilar names though :wink:

So getting back to my original problem (requesting persisted data for a specific point in time) I need to check the historicState with a Joda time like suggested by @vzorglub:

// get historic state at TripEnd time
	val dt_carEndTime = new DateTime(CarTripEnd.state.toString)
	val Number distDNAEnd = CarDistDNA.historicState(dt_carEndTime)
// log historic state at TripEnd time
	logInfo("car_state.rules", "distDNAEnd |||" + distDNAEnd + "<")

returns:

distDNAEnd |||org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1@d53e58<

When I use:

logInfo("car_state.rules", "distDNAEnd |||" + distDNAEnd + "<")

I get:

 Error during the execution of rule 'Received car trip data': 'state' is not a member of 'org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1'

YEAH!
I possibly got it - this works:

	val dt_carEndTime = new DateTime(CarTripEnd.state.toString)
	val String distDNAEnd = CarDistDNA.historicState(dt_carEndTime).state.toString

Finlly I got the solution and will post it here in detail soon.

However, I still have one issue:
The timestamp I use (start time of the trip with my car = volvo response) has an offset of 2 hrs.

What is the easiest way to change the timestamp using for the historicState request?

Start_time = Start_time.plusHours(2)

Or minusHours

Thanks - so easy… :slight_smile:
I will clean up my stuff and post the final result.
Thanks for your help, @rlkoshak & @vzorglub

I still have one question I did not consider from the beginning.
This is what works so far:

However, what I need is a Number instead of a String.
The value is stored in the DB as a Number anyway (stupid me).

So how does it look like with a Number?
I tried:

val Number distDNAEnd = CarDistDNA.historicState((dt_carStartTime).state as DecimalType).intValue

but I get:

 Error during the execution of rule 'Received car trip data': 'state' is not a member of 'org.joda.time.DateTime'; line 73, column 51, length 23

EDIT:
Got it - never mind:

val Number distDNAEnd = (CarDistDNA.historicState(dt_carEndTime).state as DecimalType).intValue

Or just

val Number distDNAEnd = CarDistDNA.historicState(dt_carEndTime).state as Number

Even better!
Thanks, Rich.

Task:
Get a state from my maria DB for a Number item (CarDistDNA) at a specific point in time (DateTime item: CarTripStart).

Solution:
Create Joda time from DateTime item (joda required for DB timestamp request):

var carStartTime = new DateTime(CarTripStart.state.toString)

create local variable with state from DB:

val Number distDNAStart = CarDistDNA.historicState(carStartTime).state as Number

Looks simple, but it took me a while with the help of @rlkoshak and @vzorglub.
Thanks guys.

Maybe it helps someone.