SQLServer提取日期中的年月日季


 

提取年:select datepart(yy,getdate()) as year

提取月:select datepart(mm,getdate()) as month

提取日:select datepart(dd,getdate()) as day

提取季度:select datepart(quarter,getdate())

------------------------------------------------------------------------------------------------------------------

Datepart():返回代表指定日期的指定日期部分的整數

 

語法:Datepart(datepart,date) 返回類型:int

 

DateName():返回代表指定日期的指定日期部分的字符串

語法:DateName(datepart,date) 返回類型:nvarchar

=====================================================

DateName(quarter,GetDate()) as ‘第幾季度’,
DateName(week,GetDate()) as ‘一年中的第幾周’,
DateName(DAYOFYEAR,GetDate()) as ‘一年中的第幾天’,
DateName(year,GetDate()) as ‘年’,
DateName(month,GetDate()) as ‘月’,
DateName(day,GetDate()) as ‘日’,
DateName(hour,GetDate()) as ‘時’,
DateName(minute,GetDate()) as ‘分’,
DateName(second,GetDate()) as ‘秒’,
DateName(MILLISECOND,GetDate()) as ‘豪秒’,
DateName(WEEKDAY,GetDate()) as ‘星期幾’

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM