How to get the first time a user logged in within 24 hours in django

You would need a model to store it in. If you have a custom User model or a user profile model, you could add a field to either of them to store it. It’s a DateTimeField that you are saving.

Ok, so you would be fine with UTC dates.

You can subtract two datetime fields, the result is a timedelta object. If that object represents more than 24 hours, then you update your model with the current time.

See the docs at Signals | Django documentation | Django to get started.

1 Like