Re: [SQL] Week of year function?

Поиск
Список
Период
Сортировка
От Kyle Bateman
Тема Re: [SQL] Week of year function?
Дата
Msg-id 3815C677.FA7E2675@actarg.com
обсуждение исходный текст
Список pgsql-sql
> At 21:52 +0200 on 22/10/1999, Zot O'Connor wrote:
>
>
> > Is there a function to return the week of the year (0-51)?
>

I use pltcl and the following function:

-- Convert date in 1999-01-15 format to the month of the year (1999,35)
-- calling sequence: date_week(ISO_date)
drop function date_week(text);
create function date_week(text) returns text as '
        set spl [split $1 {-/. }]
        set year [lindex $spl 0]
        set month [string trimleft [lindex $spl 1] 0]
        set day [lindex $spl 2]
        if {$month > 0 && $month <= 31} {
            set secs [clock scan "$month/$day/$year"]
        } else {
            set secs [clock scan "$month $day, $year"]
        }
        set week [clock format $secs -format "%U"]
        if {$week < 1} {
            return "[expr $year - 1]-52"
        }
        return "$year-$week"
        ' LANGUAGE 'pltcl';

This has some extra stuff in it you don't need, but might demonstrate
the point.


Вложения

В списке pgsql-sql по дате отправления:

Предыдущее
От: Herouth Maoz
Дата:
Сообщение: Re: [SQL] different between || and && in a statement
Следующее
От: Rich Ryan
Дата:
Сообщение: Date comparisons