假设星期从星期一开始,从 PostgreSQL 的日期字段中提取星期几 [英] Extract day of week from date field in PostgreSQL assuming weeks start on Monday
本文介绍了假设星期从星期一开始,从 PostgreSQL 的日期字段中提取星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
select extract(dow from datefield)
从 0 到 6 中提取一个数字,其中 0 是星期日;假设星期从星期一开始(所以 0 将是星期一),有没有办法在 SQL 中获取星期几?
extract a number from 0 to 6, where 0 is Sunday; is there a way to get the day of the week in SQL assuming that weeks start on Monday (so 0 will be Monday)?
推荐答案
isodow
The day of the week as Monday (1) to Sunday (7)
因此,您只需要从该结果中减去 1:
So, you just need to subtract 1 from that result:
psql (9.6.1)
Type "help" for help.
postgres=> select extract(isodow from date '2016-12-12') - 1;
?column?
-----------
0
(1 row)
postgres=>
这篇关于假设星期从星期一开始,从 PostgreSQL 的日期字段中提取星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文