RubyPDF Blog bigdata,English PostgreSQL:Get the Day Name of Week with One SQL

PostgreSQL:Get the Day Name of Week with One SQL

first show the sql,

select (array['Sun' ,'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'])
[extract(dow from  now())+1];

dow means The day of week as Sunday (0) to Saturday (6),

so you just need now the number of day of week, then you can easily convert it to the name as you wish.

the PostgreSQL array simplifies the job, otherwise we need case when or store the day name of week in another table, then inner join it.

reference,

PostgreSQL 获得星期的名字

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.