RTClib DS3231 elapsed time

Hi there!

I am using RTClib with DS3231 rtc....all works ok and i am able to get time, set time etc. But i i would need to calculate time from moment x to current time. Eg, when you press button arduino saves current time like 12/07/2018 15:00.......when you press other button it should compare current now time with saved and print out elapsed time. So if it was 12/07/2018 15:00, and now is 12/07/2018 16:45, elapsed time should be 1:45.......

Is there function to calculate this, or i should use seconds and make calculations.....

I tought on few ideas but would like to use advice on this.

Thanks!

Yes, you can get the elapsed of unixtime(), then create a new object with your elapsed time and get the variables from there.

Using seconds would work just fine.

arduino_new: Yes, you can get the elapsed of unixtime(), then create a new object with your elapsed time and get the variables from there.

I know that unixtime() returns time from 1970....what do you mean by creating new object from elapsed time while i need to calculate elapsed time?

larryd: Using seconds would work just fine.

You mean that i recalculate date to second than compare from now.time?

marinbnm: You mean that i recalculate date to second than compare from now.time?

Ok i figure out, now i would need help around math that will return sec:min:hour day/month based on second. All is clear, except this math, eg how to do calculation. If i have 3900sec which is 1hour 5min. Can i do like 3900/3600=1.08.....i take only 1, than 3900 %(modulo) 3600=300, than 3600/60=5mins?

You can let the Arduino check out your algorithm. Try printing a calculation to the serial monitor to see if you get what you think.

Remember to use the appropriate 'type' for your variables otherwise you may not get what you expect.

Use the Arduino Time library to convert unix time to date/time.