Reverts ef1662d527ec2bfdb822695b2b6cdd92842c4ad5 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 #494 (again) and #495. Use param "date_format" and a valid date() format string, defaults to "U" for a normal unix timestamp.