Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riZ7Z-000JxZ-0p for pgsql-docs@arkaria.postgresql.org; Fri, 08 Mar 2024 12:14:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1riZ7X-00CW0e-Ae for pgsql-docs@arkaria.postgresql.org; Fri, 08 Mar 2024 12:14:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1riZ7W-00CW0V-TP for pgsql-docs@lists.postgresql.org; Fri, 08 Mar 2024 12:14:39 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1riZ7Q-003R0I-7j for pgsql-docs@lists.postgresql.org; Fri, 08 Mar 2024 12:14:38 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-5134d7e16a8so1787993e87.3 for ; Fri, 08 Mar 2024 04:14:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1709900071; x=1710504871; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:to:from:subject:message-id:from:to:cc :subject:date:message-id:reply-to; bh=USgGVbYjQ0xtMlra9tqluGdwPqmyvJoYSuEVfq/Ue7U=; b=JSsnwDTOx/peX6/tjH1wugLV85mA67lhBt+z4+MihKAlNw9rfNU7Flgi0j2KumTdd6 veUV7YjVZ5Z5jAjFSIQ8USda+H19rDboSfsa+syxUrFr30hwxNWxxqv1U0dhtsccTdfA dHSR4iJuf8EfdFc40DJdbZZTQN8+vrC6dRoirpEt5587q7UIsldtTyDY2LcTUp6njuFA 2DBPu0HIDnhZqEbONa9BabBZH0FF3uudMDrJywZTBrZEoVK0qL7+DWCI2a5uJq2BAxgc l6WCSORtxWDL8VZjaWyg+hUGC5IFtS/jU/BPCHgO37HfcgvaY2NMCmN7125//Jzh0095 Z0IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709900071; x=1710504871; h=mime-version:user-agent:content-transfer-encoding:autocrypt :references:in-reply-to:date:to:from:subject:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=USgGVbYjQ0xtMlra9tqluGdwPqmyvJoYSuEVfq/Ue7U=; b=J9UxYgW2QCZRPeK3abgELfdbJhGUrRBufI2aRB/uSrFg2ajvIVzYqsyCXeEh38HHk/ QVBp4xO5RpAFlBE3NGYrGJYfK+GGQHtYfLCsA7WHzdOb0+cbxUq5pcnle64xfqHxDmxY ky9npkAbt/cwYJxJebMBL2w4E2bB5++7vToX/CiC/lF3dgnJgpntHK65mGLIvcHZorda y4I1TZq3+9zt66XtdAhDghMdKzubQKVqHOkZ+07QpHTF8bdbNbxTJjtjU9+WBXmbjjdA +oX/6+9RC3ST3H1fvqytvejJMS8nrhAAdM1BlmGJc2wrbr5YCXNUC4Idd0Uz6aO2zvKD GPQg== X-Forwarded-Encrypted: i=1; AJvYcCW3axizKfpyGb81oaGqLWXHD3mzR63YGtewm32oZYtD/fNnntKFHyL1FwFvgUjzQtfvUmDPY6tnLiKyLb2yFEpJncljP4BCuUpn+HNcC4s1 X-Gm-Message-State: AOJu0YxPEbcEGEfR706oqcaOqA8mrJY9jSpSpkpH24hTz8GkN3VlUCIw hJ5Y1bG71g2xbUicy1k+zjWImM0OXkIAQClyIPrJnXQ2T9kjzTbWVFU8JCFI8LewpmcSYBnPoAT C X-Google-Smtp-Source: AGHT+IEvaTQH2EAQXapJNT5DNCPsg3dNkIKSrVkm87smoiKcnQBsyyECQ6YKDfYaphF5HLqi+RyBpg== X-Received: by 2002:a05:6512:1107:b0:513:df6:dcd3 with SMTP id l7-20020a056512110700b005130df6dcd3mr5011255lfg.48.1709900070575; Fri, 08 Mar 2024 04:14:30 -0800 (PST) Received: from localhost.localdomain ([2001:871:5e:4fd2:a7c3:7d9e:b424:5976]) by smtp.gmail.com with ESMTPSA id n6-20020a056000170600b0033e45930f35sm11306300wrc.6.2024.03.08.04.14.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Mar 2024 04:14:30 -0800 (PST) Message-ID: Subject: Re: Issue with interval calculation when adding 1 year to a non-leap year From: Laurenz Albe To: mdriyazathcse@gmail.com, pgsql-docs@lists.postgresql.org Date: Fri, 08 Mar 2024 13:14:29 +0100 In-Reply-To: <170988464798.644.7130288736118645836@wrigleys.postgresql.org> References: <170988464798.644.7130288736118645836@wrigleys.postgresql.org> Autocrypt: addr=laurenz.albe@cybertec.at; prefer-encrypt=mutual; keydata=mQINBGGDwAQBEADgbWy5cKXQld3N2mF+DFyiNFbi2oBl2T+XgxpPF8wTRw2D/u4bBKXP0SYSE/lA86jIVNWWU0gf1KODIkVvgJm2w4vH2VBV1b7ddVViGl1Iu+9zaRnv9wulhnH42KefepXnoean6UT1EzLM0opF/Ik0j+40TxdRtobkBprkQUyHDXWlHc2ffPs3SipyFEP9AVLf7ejRC46CXWDnsqjOBSMEW8Z4HiK/8RrPZBsKLts8dJxKF4pygOdJb0CWk8k/X1jbcfdxo+zOLjOMvJcSJ2pFdJmQHU+JufB3rePziqQ2S9Ur6sccr9XnTC1GVBWN4Lf5VHq+vf+bFJjVwg+2hrySZnAVfcOrxoqFLErr7ug1zN2nM1kcpgA4VWn4gxlJtYNYYq+9WxX5dtvnNANlG3ZCrRKQzl8lxtzoF6Zo7LUhEqPaHDwn7Rvs+IdbOn41lF5UDTJGqmC4gS/bZydW2Fy3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jfzR8tIUnKscclVpOgjKaBqC+0iFiVaRqAgfOlIEiezX6kMh5Q2FIUfqs46qWhhXjRrdKOEoStYAaikdLu5ZXr7vfb0ZaDh+ZwTQtbSMFolyOkecwI81MCdbMfT/1TqIGTOdAj5as9fAakk0jb2pXgUYQ8X1DVTR8ahSDVEaw9VTmWiSvTxvguVJ1Mb7gG4Gmh6aviDTJhfXtH4rPUNXhDLqrTH8JkJjyKROOMakIF68Hjse5vUfUxreBEOtb5r1Coa2Fe7ncJayaSE7ryrDbFqpZ 36UMAx4ulWMyqJajLNGY0DdG8qIsR5nxRhrnK/mrCidZ8F9/D3bWAl4rjtHlsztN59 +AnW5l0HsQcY9ntFL/zEBOaonjdJf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.4 (3.50.4-1.fc39) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2024-03-08 at 07:57 +0000, PG Doc comments form wrote: > I have encountered a potential issue with the interval calculation when > adding 1 year to a non-leap year. The behavior observed is that when addi= ng > 1 year to a date in a non-leap year such as 2023, the resulting date is > incorrectly set to February 28th instead of February 29th in the followin= g > leap year, which should be 2024. >=20 > This behavior is inconsistent with the expected behavior, as it does not > account for leap years when performing date arithmetic using intervals. >=20 > Please find below a sample query illustrating the issue: > SELECT ('2023-02-28 23:59:59')::timestamp + INTERVAL '1 year'; >=20 > Expected result: '2024-02-29 23:59:59' > Actual result: '2024-02-28 23:59:59' If somebody tells me to meet again on the same day one year from now on Feb 28, I would show up on Feb 28 the next year. I understand that you are thinking of "the last day of the month", but with that reasoning you could say that 2023-02-27 00:00:00 + 1 year =3D 2024-02-28 00:00:00 or indeed 2023-02-01 00:00:00 + 1 year =3D 2024-02-02 00:00:00 Somewhat in favor of your interpretation is SELECT '2024-02-29 12:00:00'::timestamp - '1 year'::interval; ?column? =20 =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90 2023-02-28 12:00:00 (1 row) So we have 2024-02-29 12:00:00 - 1 year + 1 year !=3D 2024-02-29 12:00:00 and indeed 2024-02-29 12:00:00 - 1 year =3D 2024-02-28 12:00:00 - 1 year I'd say that there is simply no way to make all this consistent, and the current implementation is what I would intuitively expect. Yours, Laurenz Albe