SQL-日期函數

來源:互聯網
上載者:User

標籤:1年   目前時間   日期函數   start   ediff   number   增量   部分   函數   

GETDATE() :取得當前日期時間
DATEADD (datepart , number, date ),計算增加以後的日期。參數date為待計算的日期;參數number為增量;參數datepart為計量單位,可選值見備忘。DATEADD(DAY, 3,date)為計算日期date的3天后的日期,而DATEADD(MONTH ,-8,date)為計算日期date的8個月之前的日期 。
(入職一年以上的員工發1000$),入職日期+1年<目前時間
Sql2005中只有DateTime類型,2008中有date、datetime、datetime2 等類型。
DATEDIFF ( datepart , startdate , enddate ) :計算兩個日期之間的差額。 datepart 為計量單位,可取值參考DateAdd。
統計不同入學年數的學生個數:
select DateDiff(year,sInDate,getdate()),count(*) from student Group by DateDiff(year,sInDate,getdate())
DATEPART (datepart,date):返回一個日期的特定部分
Month()、year()、day()來代替。
統計學生的生日年份個數:
select DatePart(year,sBirthday),count(*)
from student
group by DatePart(year, sBirthday)
1990年出生的人的個數?

SQL-日期函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.