Hi all,

I'm novice in PostgreSQL.
I want to obtain current week number.
Under PHP I try:

$query = "SELECT EXTRACT(WEEK FROM NOW)";
$result= pg_exec($dbconn,$query);

where: $dbconn - successful conection id
But this give me an error message.
Can somebody help me?
Sorry for my english.

Thanks in advice.

Wodzu






Wed, 28 Nov 2001 13:09:48 +0100
"Wodzu" <wodzu@wodzus.prv.pl>
Week number
On Wed, 2001-11-28 at 13:09, Wodzu wrote:
> I'm novice in PostgreSQL.

Then pgsql-novice is the correct list to ask this kind of question.
> I want to obtain current week number.
> Under PHP I try:
> 
> $query = "SELECT EXTRACT(WEEK FROM NOW)";
> $result= pg_exec($dbconn,$query);

select date_part('week', CURRENT_TIMESTAMP);

Markus Bertheau
28 Nov 2001 15:13:43 +0100
Markus Bertheau <twanger@bluetwanger.de>
Re: Week number

Both

SELECT extract(week FROM now());

and

SELECT extract(week FROM CURRENT_TIMESTAMP);

work as expected.  I don't know which is the *accepted* SQL 92
idiom, but I would bet that it isn't 'now().'

Jason

"Wodzu" <wodzu@wodzus.prv.pl> writes:

> Hi all,
> 
> I'm novice in PostgreSQL.
> I want to obtain current week number.
> Under PHP I try:
> 
> $query = "SELECT EXTRACT(WEEK FROM NOW)";
> $result= pg_exec($dbconn,$query);
> 
> where: $dbconn - successful conection id
> But this give me an error message.
> Can somebody help me?
> Sorry for my english.
> 
> Thanks in advice.
> 
> Wodzu
> 
> 
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

28 Nov 2001 09:45:09 -0700
Jason Earl <jason.earl@simplot.com>
Re: Week number
In 7.1.x, try:

SELECT EXTRACT (WEEK FROM CURRENT_DATE);

in older postgres maybe this:

SELECT EXTRACT (WEEK FROM DATE 'today');

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Wodzu
> Sent: Wednesday, 28 November 2001 8:10 PM
> To: pgsql-hackers@postgresql.org
> Subject: [HACKERS] Week number
> 
> 
> Hi all,
> 
> I'm novice in PostgreSQL.
> I want to obtain current week number.
> Under PHP I try:
> 
> $query = "SELECT EXTRACT(WEEK FROM NOW)";
> $result= pg_exec($dbconn,$query);
> 
> where: $dbconn - successful conection id
> But this give me an error message.
> Can somebody help me?
> Sorry for my english.
> 
> Thanks in advice.
> 
> Wodzu
> 
> 
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 


Thu, 29 Nov 2001 09:43:41 +0800
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Re: Week number
> Then pgsql-novice is the correct list to ask this kind of question.
> > I want to obtain current week number.
> > Under PHP I try:
> >
> > $query = "SELECT EXTRACT(WEEK FROM NOW)";
> > $result= pg_exec($dbconn,$query);
>
> select date_part('week', CURRENT_TIMESTAMP);

I'll just point out that using date_part isn't ANSI SQL, you should use the
EXTRACT function, and the CURRENT_DATE, CURRENT_TIME and CURRENT_TIMESTAMP
variables.

Chris


Thu, 29 Nov 2001 09:47:05 +0800
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
Re: Week number