Forum Academy Marketplace Showcase Pricing Features

How to calculate Duolingo-like streaks?

Hey all!

The goal:
I’m looking for a way to search for the longest streak of days when the user had a workout

The data:
Each user can open a new Workout on any given day

The task:

  1. I want to group all workouts by days (including days with no workouts)
  2. Then calculate all workouts streaks (for example a 3 days streak, a 7 days streak etc…)
  3. Then find the longest streak

I know how to do the first step. Not sure about the next ones


Hi there, @omerbialer1… this suggestion has been made in similar threads, and it is almost certainly the way I would go if I was doing what you described. Instead of trying to figure out the streaks on the fly, store the streak from day to day in a number field. So, if a user worked out yesterday but not the day before and then they work out today, the number in the field for yesterday’s workout would be 1, and the number in the field for today’s workout would be 2. You can set the number by searching for a workout created by the current user on the previous day, and if it exists, increment the number by 1 for the current day’s workout.

Anyway, just food for thought there, and I hope it helps.


Thanks, that is a good idea!

The issue is I have a different type of streak in the app (which I didn’t forgot to mention before)

Unlike Duolingo I want to let users create workouts for previous days, which means that a user can potentially turn two streaks into on by “connecting” the retroactively

This is the reseaon I believed I would need to calculate them on the fly