Skip to content

Instantly share code, notes, and snippets.

@mastersign
Created March 23, 2024 08:39
Show Gist options
  • Select an option

  • Save mastersign/3b188d954098dcf828e48cc847fe2f6a to your computer and use it in GitHub Desktop.

Select an option

Save mastersign/3b188d954098dcf828e48cc847fe2f6a to your computer and use it in GitHub Desktop.
PostgreSQL function for converting timestamps into OLE Dates
CREATE OR REPLACE FUNCTION excel_time(in timestamp, out double precision)
AS $$
SELECT (EXTRACT(epoch FROM $1) / 86400) + 25569
$$
LANGUAGE SQL IMMUTABLE PARALLEL SAFE;
CREATE OR REPLACE FUNCTION excel_time(in timestamptz, out double precision)
AS $$
SELECT (EXTRACT(epoch FROM $1) / 86400) + 25569
$$
LANGUAGE SQL IMMUTABLE PARALLEL SAFE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment