Skip to content

Instantly share code, notes, and snippets.

@shadda
Created May 5, 2011 07:18
Show Gist options
  • Save shadda/956662 to your computer and use it in GitHub Desktop.
Save shadda/956662 to your computer and use it in GitHub Desktop.
create or replace function to_char2(v_timestamp interval, v_format varchar) returns text as $$
declare
tmp_date varchar;
begin
select to_char(v_timestamp, v_format) into tmp_date;
if found then
select
cast(cast(extract(epoch from v_timestamp) / 3600 as int) as varchar) ||
substring(tmp_date from 3) into tmp_date;
return tmp_date;
end if;
return NULL;
end;
$$ language plpgsql;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment