将日期格式化为星期几 [英] Format date as day of week
本文介绍了将日期格式化为星期几的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表,其中有一个日期列 servdate
。
I have a table which has amongst others a date column servdate
.
我使用以下查询来在过去一周内(从星期一开始的一周)为我提供所有工作:
I use the following query to get me all jobs from within the past week ( a week starts from monday):
SELECT * FROM tb1 WHERE servdate BETWEEN date('now', 'Weekday 1', '-21 days') AND date('now')
我希望查询的工作原理完全相同,但要返回 servdate
字段作为其对应的星期几。例如,星期一,而不是 2010-11-28。
I want the query to work exactly the same but instead to return the servdate
fields as their corresponding day of the week. For example, "monday", instead of "2010-11-28".
可能吗?
推荐答案
您可以使用辅助表如沃里克所建议;或者您可以使用情况
表达式:
You can use an ancillary table as wallyk suggested; or you can use a case
expression:
select _id, busnum,
case cast (strftime('%w', servdate) as integer)
when 0 then 'Sunday'
when 1 then 'Monday'
when 2 then 'Tuesday'
when 3 then 'Wednesday'
when 4 then 'Thursday'
when 5 then 'Friday'
else 'Saturday' end as servdayofweek
from tb1
where ...
这篇关于将日期格式化为星期几的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文