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