How to calculate hourly, daily, monthly etc, energy consumption from accumulated consumption?

I thought this must have been answered many times, but I cant find what Im looking for. My smartmeter outputs accumulated consumption, and I want to make a sensor that can calculate consumption pr hour, day, month etc. I know there is a Utility Meter, that probably can do this, but I want to learn a little bit of coding to try to make other sensors as well.