Skip to content

Instantly share code, notes, and snippets.

@fredbenenson
Last active January 2, 2016 21:19
Show Gist options
  • Save fredbenenson/8362536 to your computer and use it in GitHub Desktop.
Save fredbenenson/8362536 to your computer and use it in GitHub Desktop.
Seconds since midnight?
-- Note that this doesn't work:
-- SELECT DATEDIFF(second, DATE(NOW()), NOW());
-- =>
-- ERROR: function pg_catalog.date_diff("unknown", date, timestamp with time zone) does not exist
-- HINT: No function matches the given name and argument types. You may need to add explicit type casts.
-- This does work:
SELECT DATEDIFF(second, DATE(NOW()), SPLIT_PART(NOW(), '.', 1)::timestamp);
@randyzwitch
Copy link

select extract(epoch from now() - current_date);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment