detect first message and last message in the day, and save into database.