Added function to create time_distance function in PostgreSQL