This was a silly mistake. It should of course be:
!Check for time passing midnight if (the_time < last_time) { last_time = the_time; day ++; }
-- Gareth Rees