newbie:how can i get day of week data type...

Started by Muhammad Rusydialmost 25 years ago3 messagesgeneral
Jump to latest
#1Muhammad Rusydi
rusydi@cbn.net.id

i've created this table:
create table schedule (
day date,
tm timestamp,
room char(4));

insert into schedule values ('20/06/2001','08:00:00','A104');

my problem is how to get day of week information from date or is there any
way to do this?
would you show me how to do it?
thank's
Didi

#2Tamsin
tg_mail@bryncadfan.co.uk
In reply to: Muhammad Rusydi (#1)
RE: newbie:how can i get day of week data type...

use the date_part function:

test=# select date_part('dow',current_timestamp);
date_part
-----------
4
(1 row)

or:

select date_part('dow',day) from schedule;

where 'dow' is the day of week.

see the user docs for other date/time functions

hth
tamsin

Show quoted text

-----Original Message-----
From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]On Behalf Of Muhammad Rusydi
Sent: 14 June 2001 11:24
To: postgres general
Subject: [GENERAL] newbie:how can i get day of week data type...

i've created this table:
create table schedule (
day date,
tm timestamp,
room char(4));

insert into schedule values ('20/06/2001','08:00:00','A104');

my problem is how to get day of week information from date or is there any
way to do this?
would you show me how to do it?
thank's
Didi

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl

#3Jason Earl
jdearl@yahoo.com
In reply to: Muhammad Rusydi (#1)
Re: newbie:how can i get day of week data type...

The information you need can be found here:

http://www.postgresql.org/idocs/index.php?functions-datetime.html

look specifically at the extract and date_part
functions. You could get what you need by concatting
th date value and the time value (with a space in
between) casting the result as a timestamp and running
it through the date_part function using the 'dow'
parameter. Here's an example:

processdata=# select date_part('dow', ('20/06/2001' ||
' ' || '08:00:00')::timestamp);

date_part
-----------
3

The number return is an integer between 0-6 where 0 is
Sunday.

Hope this is helpful,
Jason

--- Muhammad Rusydi <rusydi@cbn.net.id> wrote:

i've created this table:
create table schedule (
day date,
tm timestamp,
room char(4));

insert into schedule values
('20/06/2001','08:00:00','A104');

my problem is how to get day of week information
from date or is there any
way to do this?
would you show me how to do it?
thank's
Didi

---------------------------(end of
broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://www.postgresql.org/search.mpl

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35
a year! http://personal.mail.yahoo.com/