Fixed SQL time interval issue