Skip to content

Instantly share code, notes, and snippets.

View majid-zandi's full-sized avatar

Majid Zandi majid-zandi

  • Iran
View GitHub Profile
@ilius
ilius / jalali-plpgsql.sql
Last active June 11, 2024 05:52
Jalali Date Conversion in PL/pgSQL
create or replace function epoch_to_jd(float) RETURNS int as $$
BEGIN
return ($1 / (24*3600) + 2440588)::int;
END;
$$ LANGUAGE plpgsql;
create or replace function timestamp_to_jd(timestamp with time zone) RETURNS int as $$
BEGIN
return epoch_to_jd(extract (epoch from $1));