Changed date function to use in PostgreSQL