一、getdate()
創(chuàng)新互聯(lián)專注于燈塔企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站定制開(kāi)發(fā)。燈塔網(wǎng)站建設(shè)公司,為燈塔等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
作用:
得到服務(wù)器當(dāng)前的時(shí)間
二、datepart(interval,date)
參數(shù):
interval:時(shí)間的某一個(gè)部分(如時(shí)、分、秒、天、周、月、季、年)
date:當(dāng)前日期或指定日期
作用:
取指定時(shí)間的某一個(gè)部分,年月天時(shí)分秒
示例:
select datepart(yy,getdate()) --year
select datepart(mm,'2012-05-01') --month
select datepart(dd,getdate()) --day
select datepart(hh,getdate()) --hour
select datepart(mi,getdate()) --min
select datepart(ss,getdate()) --sec
select datepart(weekday,getdate()) --默認(rèn)星期天為第一天,可通過(guò) set datefirst 1修改為星期一為第一天
三、datediff(interval,date,date)
參數(shù):
interval:時(shí)間的某一個(gè)部分(如時(shí)、分、秒、天、周、月、季、年)
date:當(dāng)前日期或指定日期
作用:
計(jì)算第一個(gè)日期和第二個(gè)日期在用指定的時(shí)間部分計(jì)算后的差距,第一個(gè)更大為負(fù)數(shù)
示例:
select datediff(day,'2008-10-1','2008-10-31') --30
select datediff(day,'2006-12-10','2006-11-30') --10
四、dateadd(interval, number, date)
參數(shù):
interval:間隔時(shí)間(如時(shí)、分、秒、天、周、月、季、年)
number:間隔數(shù)(正數(shù)為向后+N,負(fù)數(shù)為向前-N)
date:當(dāng)前日期或指定日期
作用:
計(jì)算指定時(shí)間,再加上表達(dá)式指定的時(shí)間長(zhǎng)度
示例:
select dateadd(hour,1,getdate()) --時(shí)
select dateadd(minute,1,getdate()) --分
select dateadd(second,1,getdate()) --秒
select dateadd(day,1,getdate()) --天
select dateadd(week,1,getdate()) --周
select dateadd(month,1,getdate()) --月
select dateadd(quarter,1,getdate()) --季
select dateadd(year,1,getdate()) --年
五、convert(type,date,style)
參數(shù):
type:要轉(zhuǎn)換為的目標(biāo)數(shù)據(jù)類型(如char、int)
date:需要轉(zhuǎn)換的日期
style:規(guī)定的時(shí)間/日期格式的編碼(如101、102)
作用:
把日期轉(zhuǎn)換為其他的類型和指定格式的數(shù)據(jù)
示例:
select convert(char,getdate(),101) --'09/27/2003'
select convert(char,getdate(),102) --'2003.11.12'
select convert(char,getdate(),103) --'27/09/2003'
select convert(char,getdate(),104) --'27.09.2003'
select convert(char,getdate(),105) --'27-09-2003'
select convert(char,getdate(),106) --'27 Sep 2003'
select convert(char,getdate(),107) --'Sep 27, 2003'
select convert(char,getdate(),108) --'11:16:06'
select convert(char,getdate(),109) --'Sep 27 2003 11:16:28:746AM'
select convert(char,getdate(),110) --'09-27-2003'
select convert(char,getdate(),111) --'2003/09/27'
select convert(char,getdate(),112) --'20030927'
select convert(char,getdate(),120) --'2012-05-01 14:21:40'
網(wǎng)站題目:SybaseIQ-日期函數(shù)
網(wǎng)站網(wǎng)址:http://chinadenli.net/article26/jdpdjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、網(wǎng)站設(shè)計(jì)公司、服務(wù)器托管、網(wǎng)站導(dǎo)航、ChatGPT、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)