updated for MS-SQL compatibility

DATE_FORMAT not recognized by MS-SQL. Edited line 85 to remove DATE_FORMAT and change to a 'convert' statement part. Needs to be tested with mysql and postgres.