From: | Kyle Bateman <kyle(at)actarg(dot)com> |
---|---|
To: | zot(at)zotconsulting(dot)com |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: [SQL] Week of year function? |
Date: | 1999-10-26 15:19:19 |
Message-ID: | 3815C677.FA7E2675@actarg.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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.
Attachment | Content-Type | Size |
---|---|---|
kyle.vcf | text/x-vcard | 291 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | omid omoomi | 1999-10-27 05:29:18 | Re: [SQL] Date comparisons |
Previous Message | Herouth Maoz | 1999-10-26 14:28:17 | Re: [SQL] different between || and && in a statement |