# How to count the offline time

I want to make a app, that can remebers how many days the last run of this apk was.
I think I have to workin with somthing like DateTime.
But how can I compare the datetime values from 4 days ago with the current work in order to then execute an if accordingly if the app has not been used for more than 4 days, which is calculated from the distance between the last Datetime.Now and the new one. that results when the app is started for the first time. The old value is retained and saved by this asset:

But how can I compare the datetime values from 4 days ago with the current work in order to then execute an if accordingly if the app has not been used for more than 4 days, which is calculated from the distance between the last Datetime.Now and the new one. that results when the app is started for the first time. The old value is retained and saved by this asset:

You can subtract one DateTime from another to get a TimeSpan representing the elapsed time between them.

1 Like

You can use the UTC time, so you save it when exiting and then compare to current value when game is loaded again to get amount of seconds in between the 2.

Hereâ€™s an example implementation: uStableObject/uStableObject/Time/TimeProviderUTC.cs at master Â· met44/uStableObject Â· GitHub

I donâ€™t quite understand what youâ€™re asking. But whenever I need to determine the amount of time the game has been closed, I prefer using DateTime.Now.Ticks. It is trivial to convert to seconds, hours, days, etc, and I find doing my own simple math with just a â€ślongâ€ť is a lot faster and easier to wrap my head around than dealing with the rest of the DateTime class.

you get accurate results doing that even when changing machines ?

According to this, the number of DateTime â€śticksâ€ť per second is a constant, not machine-dependent.

1 Like