Обсуждение: Get day name(Mon, Tue... Sun) and day number (1, 2...7) from a date

Поиск
Список
Период
Сортировка

Get day name(Mon, Tue... Sun) and day number (1, 2...7) from a date

От
Emi Lu
Дата:
Good morning,

Could someone tell me the command to get the weekly day name and day 
number please.


I am expecting something like:

sql> select data_part('day name', current_date);
sql> Monday

sql> select data_part('day number', current_date);
sql> 1

(Mon =1 ... Sun =7?)

Thanks a lot!


Re: Get day name(Mon, Tue... Sun) and day number (1, 2...7) from a date

От
"Milen A. Radev"
Дата:
Emi Lu написа:
> Good morning,
> 
> Could someone tell me the command to get the weekly day name and day 
> number please.
> 
> 
> I am expecting something like:
> 
> sql> select data_part('day name', current_date);
> sql> Monday
> 
> sql> select data_part('day number', current_date);
> sql> 1
> 
> (Mon =1 ... Sun =7?)

You need "TO_CHAR" 
(http://www.postgresql.org/docs/current/static/functions-formatting.html) 
- "SELECT to_char(current_date, 'Dy')".


-- 
Milen A. Radev



Re: Get day name(Mon, Tue... Sun) and day number (1, 2...7) from a date

От
"Pavel Stehule"
Дата:
Hello

use to_char function
postgres=# select to_char(current_date, 'day'); to_char
-----------wednesday
(1 row)

postgres=# select extract(dow from  current_date);date_part
-----------        3
(1 row)

regards
Pavel

2008/7/30 Emi Lu <emilu@encs.concordia.ca>:
> Good morning,
>
> Could someone tell me the command to get the weekly day name and day number
> please.
>
>
> I am expecting something like:
>
> sql> select data_part('day name', current_date);
> sql> Monday
>
> sql> select data_part('day number', current_date);
> sql> 1
>
> (Mon =1 ... Sun =7?)
>
> Thanks a lot!
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>


Re: Get day name(Mon, Tue... Sun) and day number (1, 2...7) from a date

От
Bricklen Anderson
Дата:
Emi Lu wrote:
> Good morning,
> 
> Could someone tell me the command to get the weekly day name and day 
> number please.
> 
> 
> I am expecting something like:
> 
> sql> select data_part('day name', current_date);
> sql> Monday
> 
> sql> select data_part('day number', current_date);
> sql> 1
> 
> (Mon =1 ... Sun =7?)
> 
> Thanks a lot!
> 

http://www.postgresql.org/docs/current/static/functions-formatting.html


select to_char(current_date,'Day');
select to_char(current_date,'D');


Re: Get day name(Mon, Tue... Sun) and day number (1, 2...7) from a date

От
Emi Lu
Дата:
>>
>> I am expecting something like:
>>
>> sql> select data_part('day name', current_date);
>> sql> Monday
>>
>> sql> select data_part('day number', current_date);
>> sql> 1
>>
>> (Mon =1 ... Sun =7?)
>>
>> Thanks a lot!
>>
> 
> http://www.postgresql.org/docs/current/static/functions-formatting.html


This is exactly what I am looking for.
> select to_char(current_date,'Day');> select to_char(current_date,'D');

1: Sunday
2: Monday
3: Tuesday
4: Wednesday
5: Thursday
6: Friday
7: Saturday

Thank you very much for all your inputs!