How to calculate streaks of consecutive dates for a user
To keep track of longest streak and when it occurred.

Table columns needed:

current_streak          int
longest_streak          int
longest_streak_end_date datetime


Pseudocode:

if user has logged in today already
    return
if user logged in yesterday
    add 1 to current_streak
    if current_streak &gt; longest_streak
        set longest_streak = current_streak
        set longest_streak_end_date = today
else
    set current_streak = 1