ä¸ãDateAdd()æ¹æ³è¯´æ
SQL Serveræä¾äºæ¥æå½æ°DateAddç¨äºè·å¾ææ¥ææå®é´éåçæ¥æã
1. å®ä¹åç¨æ³
DATEADD() å½æ°å¨æ¥æä¸æ·»å æåå»æå®çæ¶é´é´éã
2. è¯æ³
DATEADD(datepart,number,date)
date åæ°æ¯åæ³çæ¥æ表达å¼ãnumber æ¯æ¨å¸ææ·»å çé´éæ°ï¼å¯¹äºæªæ¥çæ¶é´ï¼æ¤æ°æ¯æ£æ°ï¼å¯¹äºè¿å»çæ¶é´ï¼æ¤æ°æ¯è´æ°ã
datepart åæ°å¯ä»¥æ¯ä¸åçå¼ï¼
datepart
缩å
å¹´ yy, yyyy
å£åº¦ qq, q
æ mm, m
å¹´ä¸çæ¥ dy, y
æ¥ dd, d
å¨ wk, ww
ææ dw, w
å°æ¶ hh
åé mi, n
ç§ ss, s
æ¯«ç§ ms
å¾®å¦ mcs
çº³ç§ ns
å®ä¾
å设æ们æä¸é¢è¿ä¸ª "Orders" 表ï¼
OrderId
ProductName
OrderDate
'Computer' 2016-12-29 16:25:46.635
ç°å¨ï¼æ们å¸æå "OrderDate" æ·»å 2 天ï¼è¿æ ·å°±å¯ä»¥æ¾å°ä»æ¬¾æ¥æã
æ们使ç¨å¦ä¸ SELECT è¯å¥ï¼
SELECT OrderId,DATEADD(day,2,OrderDate) AS OrderPayDate
FROM Orders
ç»æï¼
OrderId
OrderPayDate
2016-12-31 16:25:46.635
äºãSQL代ç
PRINT DateAdd(day, 100, GetDate())ä¸ãè¿è¡æµè¯
08 31 2017 2:56PM