{"id":499,"date":"2026-02-02T05:17:07","date_gmt":"2026-02-02T05:17:07","guid":{"rendered":"http:\/\/77interactive.com\/?p=499"},"modified":"2026-02-02T05:17:27","modified_gmt":"2026-02-02T05:17:27","slug":"calendar-basic","status":"publish","type":"post","link":"http:\/\/77interactive.com\/?p=499","title":{"rendered":"Calendar Basic"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>-- Use or create database (adjust as needed)\n-- \\c test;\n\nDROP TABLE IF EXISTS calendar_basic;\n\nCREATE TABLE calendar_basic (\n    date_id INT NOT NULL PRIMARY KEY,\n    full_date DATE NOT NULL,\n    date_name VARCHAR(10) NOT NULL,\n    year_month INT,\n    year_week INT,\n    yqmd VARCHAR(10) NOT NULL,\n    day_of_week INT NOT NULL,\n    day_of_week_name VARCHAR(10) NOT NULL,\n    day_of_month INT NOT NULL,\n    month_name VARCHAR(10) NOT NULL,\n    month_abbr VARCHAR(3) NOT NULL,\n    day_of_year INT NOT NULL,\n    is_week_day BOOLEAN NOT NULL,\n    is_weekend_day BOOLEAN NOT NULL,\n    is_holiday BOOLEAN NOT NULL,\n    week_of_year INT NOT NULL,\n    month_of_year INT NOT NULL,\n    is_last_day_of_month BOOLEAN NOT NULL,\n    calendar_quarter INT NOT NULL,\n    calendar_semester INT NOT NULL,\n    calendar_year INT NOT NULL,\n    fiscal_month_of_year INT NOT NULL,\n    fiscal_quarter INT NOT NULL,\n    fiscal_semester INT NOT NULL,\n    fiscal_year INT NOT NULL\n);\n\nDO $$\nDECLARE\n    process_date DATE;\nBEGIN\n    process_date := '2000-01-01'::DATE;\n    \n    WHILE process_date &lt;= '2030-12-31'::DATE LOOP\n        INSERT INTO calendar_basic (\n            date_id,\n            full_date,\n            date_name,\n            year_month,\n            year_week,\n            yqmd,\n            day_of_week,\n            day_of_week_name,\n            day_of_month,\n            month_name,\n            month_abbr,\n            day_of_year,\n            is_week_day,\n            is_weekend_day,\n            is_holiday,\n            week_of_year,\n            month_of_year,\n            is_last_day_of_month,\n            calendar_quarter,\n            calendar_semester,\n            calendar_year,\n            fiscal_month_of_year,\n            fiscal_quarter,\n            fiscal_semester,\n            fiscal_year\n        )\n        SELECT \n            TO_CHAR(process_date, 'YYYYMMDD')::INT AS date_id,\n            process_date AS full_date,\n            TO_CHAR(process_date, 'YYYY-MM-DD') AS date_name,\n            TO_CHAR(process_date, 'YYYYMM')::INT AS year_month,\n            (TO_CHAR(process_date, 'YYYY') || LPAD(EXTRACT(WEEK FROM process_date)::TEXT, 2, '0'))::INT AS year_week,\n            (TO_CHAR(process_date, 'YYYY') || '0' || EXTRACT(QUARTER FROM process_date)::TEXT || \n             LPAD(EXTRACT(MONTH FROM process_date)::TEXT, 2, '0') || \n             LPAD(EXTRACT(DAY FROM process_date)::TEXT, 2, '0'))::VARCHAR(10) AS yqmd,\n            EXTRACT(ISODOW FROM process_date)::INT AS day_of_week,\n            TO_CHAR(process_date, 'Day')::VARCHAR(10) AS day_of_week_name,\n            EXTRACT(DAY FROM process_date)::INT AS day_of_month,\n            TO_CHAR(process_date, 'Month')::VARCHAR(10) AS month_name,\n            TO_CHAR(process_date, 'Mon')::VARCHAR(3) AS month_abbr,\n            EXTRACT(DOY FROM process_date)::INT AS day_of_year,\n            CASE \n                WHEN EXTRACT(ISODOW FROM process_date) NOT IN (6, 7) THEN TRUE\n                ELSE FALSE\n            END AS is_week_day,\n            CASE \n                WHEN EXTRACT(ISODOW FROM process_date) IN (6, 7) THEN TRUE\n                ELSE FALSE\n            END AS is_weekend_day,\n            FALSE AS is_holiday,\n            EXTRACT(WEEK FROM process_date)::INT AS week_of_year,\n            EXTRACT(MONTH FROM process_date)::INT AS month_of_year,\n            CASE \n                WHEN EXTRACT(MONTH FROM process_date) &lt;> EXTRACT(MONTH FROM process_date + INTERVAL '1 day') THEN TRUE\n                ELSE FALSE\n            END AS is_last_day_of_month,\n            EXTRACT(QUARTER FROM process_date)::INT AS calendar_quarter,\n            CASE \n                WHEN EXTRACT(MONTH FROM process_date) &lt; 7 THEN 1\n                ELSE 2\n            END AS calendar_semester,\n            EXTRACT(YEAR FROM process_date)::INT AS calendar_year,\n            EXTRACT(MONTH FROM process_date)::INT AS fiscal_month_of_year,\n            EXTRACT(QUARTER FROM process_date)::INT AS fiscal_quarter,\n            CASE \n                WHEN EXTRACT(MONTH FROM process_date) &lt; 7 THEN 1\n                ELSE 2\n            END AS fiscal_semester,\n            EXTRACT(YEAR FROM process_date)::INT AS fiscal_year;\n        \n        process_date := process_date + INTERVAL '1 day';\n    END LOOP;\nEND $$;\n\n-- Test query\nSELECT *\nFROM calendar_basic\nWHERE date_id >= 20260101\nORDER BY date_id\nLIMIT 1;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":500,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[17,18],"class_list":["post-499","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-postgresql","tag-postgres","tag-postgresql"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Calendar Basic - 77 Interactive<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/77interactive.com\/?p=499\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Calendar Basic - 77 Interactive\" \/>\n<meta property=\"og:url\" content=\"http:\/\/77interactive.com\/?p=499\" \/>\n<meta property=\"og:site_name\" content=\"77 Interactive\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-02T05:17:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-02T05:17:27+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Rudy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rudy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/77interactive.com\/?p=499#article\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/?p=499\"},\"author\":{\"name\":\"Rudy\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"headline\":\"Calendar Basic\",\"datePublished\":\"2026-02-02T05:17:07+00:00\",\"dateModified\":\"2026-02-02T05:17:27+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=499\"},\"wordCount\":2,\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=499#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png\",\"keywords\":[\"postgres\",\"postgresql\"],\"articleSection\":[\"PostgreSQL\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/77interactive.com\/?p=499\",\"url\":\"http:\/\/77interactive.com\/?p=499\",\"name\":\"Calendar Basic - 77 Interactive\",\"isPartOf\":{\"@id\":\"http:\/\/77interactive.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/77interactive.com\/?p=499#primaryimage\"},\"image\":{\"@id\":\"http:\/\/77interactive.com\/?p=499#primaryimage\"},\"thumbnailUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png\",\"datePublished\":\"2026-02-02T05:17:07+00:00\",\"dateModified\":\"2026-02-02T05:17:27+00:00\",\"author\":{\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\"},\"breadcrumb\":{\"@id\":\"http:\/\/77interactive.com\/?p=499#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/77interactive.com\/?p=499\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/?p=499#primaryimage\",\"url\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png\",\"contentUrl\":\"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png\",\"width\":1024,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/77interactive.com\/?p=499#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/77interactive.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Calendar Basic\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/77interactive.com\/#website\",\"url\":\"http:\/\/77interactive.com\/\",\"name\":\"77 Interactive\",\"description\":\"Rudy&#039;s Code snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/77interactive.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9\",\"name\":\"Rudy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/77interactive.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g\",\"caption\":\"Rudy\"},\"url\":\"http:\/\/77interactive.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Calendar Basic - 77 Interactive","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/77interactive.com\/?p=499","og_locale":"en_US","og_type":"article","og_title":"Calendar Basic - 77 Interactive","og_url":"http:\/\/77interactive.com\/?p=499","og_site_name":"77 Interactive","article_published_time":"2026-02-02T05:17:07+00:00","article_modified_time":"2026-02-02T05:17:27+00:00","og_image":[{"width":1024,"height":1024,"url":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png","type":"image\/png"}],"author":"Rudy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rudy","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/77interactive.com\/?p=499#article","isPartOf":{"@id":"http:\/\/77interactive.com\/?p=499"},"author":{"name":"Rudy","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"headline":"Calendar Basic","datePublished":"2026-02-02T05:17:07+00:00","dateModified":"2026-02-02T05:17:27+00:00","mainEntityOfPage":{"@id":"http:\/\/77interactive.com\/?p=499"},"wordCount":2,"image":{"@id":"http:\/\/77interactive.com\/?p=499#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png","keywords":["postgres","postgresql"],"articleSection":["PostgreSQL"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"http:\/\/77interactive.com\/?p=499","url":"http:\/\/77interactive.com\/?p=499","name":"Calendar Basic - 77 Interactive","isPartOf":{"@id":"http:\/\/77interactive.com\/#website"},"primaryImageOfPage":{"@id":"http:\/\/77interactive.com\/?p=499#primaryimage"},"image":{"@id":"http:\/\/77interactive.com\/?p=499#primaryimage"},"thumbnailUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png","datePublished":"2026-02-02T05:17:07+00:00","dateModified":"2026-02-02T05:17:27+00:00","author":{"@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9"},"breadcrumb":{"@id":"http:\/\/77interactive.com\/?p=499#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/77interactive.com\/?p=499"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/?p=499#primaryimage","url":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png","contentUrl":"http:\/\/77interactive.com\/wp-content\/uploads\/2026\/02\/Copilot_20260201_231634.png","width":1024,"height":1024},{"@type":"BreadcrumbList","@id":"http:\/\/77interactive.com\/?p=499#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/77interactive.com\/"},{"@type":"ListItem","position":2,"name":"Calendar Basic"}]},{"@type":"WebSite","@id":"http:\/\/77interactive.com\/#website","url":"http:\/\/77interactive.com\/","name":"77 Interactive","description":"Rudy&#039;s Code snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/77interactive.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/77interactive.com\/#\/schema\/person\/0e61d2a984b8304618026b207e6121e9","name":"Rudy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/77interactive.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e336b9aecd39b40691ff8ccfcd68506415072dbe8caffc0485b94a1bc22b774d?s=96&d=mm&r=g","caption":"Rudy"},"url":"http:\/\/77interactive.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=499"}],"version-history":[{"count":1,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions"}],"predecessor-version":[{"id":501,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/posts\/499\/revisions\/501"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=\/wp\/v2\/media\/500"}],"wp:attachment":[{"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=499"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/77interactive.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}