From: Andrew Gierth <andrew@tao11.riddles.org.uk>
To: Sreeni Survi <sreenisurvi@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: to_char function returning wrong data
Date: Mon, 04 Feb 2019 17:25:19 +0000
Message-ID: <87munb5v24.fsf@news-spur.riddles.org.uk> (raw)
In-Reply-To: <CAD91y4RLdbXvr+oNoN++Wmn2SjxHYRJZnT95f=BPZcSO0OBTxg@mail.gmail.com>
References: <CAD91y4RLdbXvr+oNoN++Wmn2SjxHYRJZnT95f=BPZcSO0OBTxg@mail.gmail.com>
>>>>> "Sreeni" == Sreeni Survi <sreenisurvi@gmail.com> 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)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: andrew@tao11.riddles.org.uk, sreenisurvi@gmail.com
Subject: Re: to_char function returning wrong data
In-Reply-To: <87munb5v24.fsf@news-spur.riddles.org.uk>
References: <CAD91y4RLdbXvr+oNoN++Wmn2SjxHYRJZnT95f=BPZcSO0OBTxg@mail.gmail.com> <87munb5v24.fsf@news-spur.riddles.org.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox