Extract datetime range data from sensor

Is there a way to retrieve historical data from a sensor but using a set datetime range?

So I have a sensor that records power consumption over time. However I need to get data let’s say from Jan to Feb rather than the current state.
I have a date time helper with the from and to dates just not sure how to apply it to a sensor.

Thanks in advance.

I did the same today, exported as CSV file, using a custom HACS history card.

@zillion42 thanks but I was thinking more around getting the data from the db of history or somehow reading the sensor data and extracting a custom range on the go with a template or something.
But not sure if this is doable. The data is there and it can be found using history. But that doesn’t add the figure.
So looking for a custom date range that will retrieve the value of consumption between those dates.

The closest I got to this is using SQL integration. However due to retention I can only go back 10 days.