Access拆分日期爲年,季度,月,週等具體時間

2017-10-11 17:19:00
tmtony8
原創
3404

有些時候,我們需要在日期中篩選某季度或者某一週的內容。

如有下麵這樣的一箇錶格。有數量甚多的日期內容。需要通過查詢篩選齣相關的信息


這裡我們首先需要對日期劃分齣具體的年份,季度,月,週,日期等等。再通過具體的窗體去查詢


詳細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;


    分享