按月統計員工登入情況及日期函數的運用__函數

來源:互聯網
上載者:User

select month(LOGINTIME),count(id) from s_login_log group by month(LOGINTIME)


日期函數

select day(createtime) from life_unite_product     --取時間欄位的天值
select month(createtime) from life_unite_product   --取時間欄位的月值
select year(createtime) from life_unite_product    --取時間欄位的年值


select datepart(yy,createtime) from life_unite_product     --取時間欄位的年值
select datepart(qq,createtime) from life_unite_product     --取時間欄位的季度值
select datepart(mm,createtime) from life_unite_product     --取時間欄位的月值
select datepart(dy,createtime) from life_unite_product     --取時間欄位是那年的第幾天
select datepart(dd,createtime) from life_unite_product     --取時間欄位的天值
select datepart(wk,createtime) from life_unite_product       --取時間欄位是那年的第幾個星期
select datepart(dw,createtime) from life_unite_product       --取時間欄位是那年的那個星期的第幾個工作日(工作日從星期日開算)
select datepart(hh,createtime) from life_unite_product     --取時間欄位的小時值
select datepart(mi,createtime) from life_unite_product     --取時間欄位的分鐘值
select datepart(ss,createtime) from life_unite_product     --取時間欄位的秒值
select datepart(ms,createtime) from life_unite_product     --取時間欄位的毫秒值


select dateadd(yy,-1,createtime) from life_unite_product   ----取時間欄位(年份被減1了)
select dateadd(mm,3,createtime) from life_unite_product   ----取時間欄位(月份被加3了)
select dateadd(dd,1,createtime) from life_unite_product   ----取時間欄位(日被加1了)


select DATEDIFF(yy,createtime,getdate()) from life_unite_product --與當前日期的年份差
select DATEDIFF(mm,createtime,getdate()) from life_unite_product --與當前日期的月份差
select DATEDIFF(dd,createtime,getdate()) from life_unite_product --與當前日期的日數差
select DATEDIFF(mi,createtime,getdate()) from life_unite_product --與當前日期的分鐘數差

select datename(yy,createtime) from life_unite_product   --取時間欄位的年值
select datename(mm,createtime) from life_unite_product   --取時間欄位的月值
select datename(dd,createtime) from life_unite_product   --取時間欄位的天值

select getdate()   --取目前時間


1、day(date_expression)
返回date_expression中的日期值


2、month(date_expression)
返回date_expression中的月份值


3、year(date_expression)
返回date_expression中的年份值


4、DATEADD()

DATEADD (, , )

返回指定日期date 加上指定的額外日期間隔number 產生的新日期。參數“datepart” 取值如下:


5、DATEDIFF()

DATEDIFF (, , )
返回兩個指定日期在datepart 方面的不同之處,即date2 超過date1的差距值,其結果值是一個帶有加號或減號的整數值。


6、DATENAME()

DATENAME (, )
以字串的形式返回日期的指定部分此部分。由datepart 來指定。


7、DATEPART()

DATEPART ( datepart , date )
以整數值的形式返回日期的指定部分。此部分由datepart 來指定。


DATEPART (dd, date) 等同於DAY (date)
DATEPART (mm, date) 等同於MONTH (date)
DATEPART (yy, date) 等同於YEAR (date)

下表列出了 datepart 選項以及 SQL Server Compact Edition 所識別的縮寫:

日期部分        縮寫 
年份            yy、yyyy 
季度            qq、q 
月份            mm、m 
每年的某一日    dy、y 
日期            dd、d 
星期            wk、ww 
工作日*         dw
小時            hh 
分鐘            mi、n 
秒              ss、s 
毫秒            ms

8、GETDATE()
以DATETIME 的預設格式返回系統當前的日期和時間

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.