updated sql and fixed date format