pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #6219: date_part() function producting incorrect year
2+ messages / 2 participants
[nested] [flat]

* BUG #6219: date_part() function producting incorrect year
@ 2011-09-21 21:17 Eric Vollnogel <edvollnogel@dstsystems.com>
  2011-09-21 21:47 ` Re: BUG #6219: date_part() function producting incorrect year Guillaume Smet <guillaume.smet@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Eric Vollnogel @ 2011-09-21 21:17 UTC (permalink / raw)
  To: pgsql-bugs


The following bug has been logged online:

Bug reference:      6219
Logged by:          Eric Vollnogel
Email address:      edvollnogel@dstsystems.com
PostgreSQL version: 9.0.4 64bit
Operating system:   Windows 7 SP 1 64bit
Description:        date_part() function producting incorrect year
Details: 

The date_part('isoyear', some_column) function is not always returning the
correct result.  See below:

Example 1: (date_part returns incorrect year)

SQL: 
SELECT date_part('isoyear', observation_start), observation_start FROM
service_point_observations
WHERE observation_start >= '2011-01-01'
  AND observation_start < '2011-01-02'
LIMIT 5;

Output:
2010;"2011-01-01 00:00:00-06"
2010;"2011-01-01 00:00:00-06"
2010;"2011-01-01 00:00:00-06"
2010;"2011-01-01 00:00:00-06"
2010;"2011-01-01 00:00:00-06"

Example 2: (date_part returns incorrect year)

SQL: 
SELECT date_part('isoyear', observation_start), observation_start FROM
service_point_observations
WHERE observation_start >= '2011-01-02'
  AND observation_start < '2011-01-03'
LIMIT 5;

Output:
2010;"2011-01-02 00:00:00-06"
2010;"2011-01-02 00:00:00-06"
2010;"2011-01-02 00:00:00-06"
2010;"2011-01-02 00:00:00-06"
2010;"2011-01-02 00:00:00-06"

Example 2: (date_part returns CORRECT year)

SQL: 
SELECT date_part('isoyear', observation_start), observation_start FROM
service_point_observations
WHERE observation_start >= '2011-01-03'
  AND observation_start < '2011-01-04'
LIMIT 5;

Output:
2011;"2011-01-03 00:00:00-06"
2011;"2011-01-03 00:00:00-06"
2011;"2011-01-03 00:00:00-06"
2011;"2011-01-03 00:00:00-06"
2011;"2011-01-03 00:00:00-06"

Thank you for your assistance,

ERIC VOLLNOGEL



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #6219: date_part() function producting incorrect year
  2011-09-21 21:17 BUG #6219: date_part() function producting incorrect year Eric Vollnogel <edvollnogel@dstsystems.com>
@ 2011-09-21 21:47 ` Guillaume Smet <guillaume.smet@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Guillaume Smet @ 2011-09-21 21:47 UTC (permalink / raw)
  To: Eric Vollnogel <edvollnogel@dstsystems.com>; +Cc: pgsql-bugs

On Wed, Sep 21, 2011 at 11:17 PM, Eric Vollnogel
<edvollnogel@dstsystems.com> wrote:
> The date_part('isoyear', some_column) function is not always returning the
> correct result.  See below:

See http://www.postgresql.org/docs/8.4/static/functions-datetime.html :
"Each ISO year begins with the Monday of the week containing the 4th
of January, so in early January or late December the ISO year may be
different from the Gregorian year. See the week field for more
information."

So ISO year 2011 starts on Monday the 3rd of January.

If you want the Gregorian year, just user 'year' instead of 'isoyear'.

-- 
Guillaume



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2011-09-21 21:47 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-09-21 21:17 BUG #6219: date_part() function producting incorrect year Eric Vollnogel <edvollnogel@dstsystems.com>
2011-09-21 21:47 ` Guillaume Smet <guillaume.smet@gmail.com>

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