Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gqhzr-0006I8-DU for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Feb 2019 17:25:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gqhzq-0008PG-6I for pgsql-bugs@arkaria.postgresql.org; Mon, 04 Feb 2019 17:25:26 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gqhzp-0008MC-Ul for pgsql-bugs@lists.postgresql.org; Mon, 04 Feb 2019 17:25:25 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gqhzn-0007US-Pe for pgsql-bugs@postgresql.org; Mon, 04 Feb 2019 17:25:25 +0000 Received: from [192.168.127.1] (port=24866 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1gqhzl-0002Hw-7i; Mon, 04 Feb 2019 17:25:21 +0000 Received: from [127.0.0.1] (port=47054 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gqhzk-000DGN-1q; Mon, 04 Feb 2019 17:25:20 +0000 From: Andrew Gierth To: Sreeni Survi Cc: pgsql-bugs@postgresql.org Subject: Re: to_char function returning wrong data In-Reply-To: (Sreeni Survi's message of "Mon, 4 Feb 2019 12:16:06 -0500") Message-ID: <87munb5v24.fsf@news-spur.riddles.org.uk> References: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) X-Mayan-Date: Long count = 13.0.6.3.16; tzolkin = 4 Cib; haab = 9 Pax Date: Mon, 04 Feb 2019 17:25:19 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Sreeni" == Sreeni Survi writes: Sreeni> Hi, Sreeni> Below code has caused my data to be wiped off a table as my Sreeni> where clause depends on the below returned value. Sreeni> *select to_char(current_date - interval '5 weeks','IYYYWW') ;* Sreeni> *201953* That's because IYYY is intended for use with IW, not with WW. The output is correct, it's the query that's wrong. There are several different definitions of "week number", and IW is the ISO week, with IYYY being the corresponding year. So 5 weeks ago, which was Dec 31st 2018, was ISO week 1 of 2019, but in some other week numbering systems, it was week 53 of 2018. -- Andrew (irc:RhodiumToad)