fixed bug with date in sql