Re: date_trunct() and start of week

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: date_trunct() and start of week
Date: 2009-11-26 22:17:10
Message-ID: bddc86150911261417n5ed5e0a7s4e9e7e092132ce0f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2009/11/26 Thomas Kellerer <spam_eater(at)gmx(dot)net>

> Hi,
>
> while using date_trunc('week', some_date) to get the date of the first day
> of the week I noticed that it was working as expected: Monday is considered
> the start of the week.
> I assume this depends on some locale setting, but I can't figure out which
> it is, so I can make sure this is not "accidently" changed. I tried changing
> LC_TIME (American_America) but that still returned Monday as the first day
> (my understanding is that in the States Sunday is considered the start of
> the week)
>
> Any pointers are appreciated (did I miss it in the manual?)
>
> Regards
> Thomas
>
>
> I don't understand how date_trunc is giving you the day of the week. As
far as I'm aware it only reduces the precision of the date/time. What I
imagine you'd use is: extract(DOW from some_date). This won't be
locale-dependant. It will always be 0 (Sunday) - 6 (Saturday). There is
another way to get the day of the week which is to_char(some_date, 'D')
which is numbered 1 (Sunday) to 7 (Saturday).

Regards

Thom

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thom Brown 2009-11-26 22:18:53 Re: date_trunct() and start of week
Previous Message Adrian Klaver 2009-11-26 22:15:09 Re: date_trunct() and start of week