Reverts 4c1858db5a45f39fbd53649dbb4c0c766cdd591f and re-implements this functionality in a more generic fashion and for all other implementations where this is theoretically possible. Also fixes a GC bug with pgsql. Closes #569 (again) and #570. Use param "date_format" and a valid date() format string, defaults to "U" for a normal unix timestamp.