Access拆分日期为年,季度,月,周等具体时间

2017-10-11 17:19:00
黄善超
原创
353

有些时候,我们需要在日期中筛选某季度或者某一周的内容。

如有下面这样的一个表格。有数量甚多的日期内容。需要通过查询筛选出相关的信息


这里我们首先需要对日期划分出具体的年份,季度,月,周,日期等等。再通过具体的窗体去查询


详细sql语句:

SELECT 表1.日期, 表1.编号, Weekday([日期])-1 AS 星期, IIf(Weekday(表1!日期)=1,"星期日",IIf(Weekday(表1!日期)=2,"星期一",IIf(Weekday(表1!日期)=3,"星期二",IIf(Weekday(表1!日期)=4,"星期三",IIf(Weekday(表1!日期)=5,"星期四",IIf(Weekday(表1!日期)=6,"星期五",IIf(Weekday(表1!日期)=7,"星期六"))))))) AS 中文星期, Format([日期],"yyyy/ww") AS 年第几周, Format([日期],"ww") AS 第几周, "第" & DatePart("q",表1!日期,1,0) & "季度" AS 第季度, DatePart("q",表1!日期,1,0) AS 季度, Format(表1!日期,"ww")-Format((表1!日期-Day(表1!日期)+1),"ww")+1 AS 月第几周, 表1!日期-Day(表1!日期)+1 AS 月初, Year([日期]) AS 年, Month([日期]) AS 月, Day([日期]) AS 日
FROM 表1;


    分享