1
/**/
/* datepart()函数的使用
2
* datepart()函数可以方便的取到时期中的各个部分
3
*如日期:2006-07--02 18:15:36.513
4
* yy:取年 2006
5
* mm:取月 7
6
* dd:取月中的天 2
7
* dy:取年中的天 183
8
* wk:取年中的周 27
9
* dw:取周中的天 1
10
* qq:取年中的季度 3
11
* hh:取小时 18
12
* mi:取分钟 15
13
* ss:取秒 36
14
* 以下简单的语句可以演示所取到的结果
15
*/
16
select
getdate
()
17
select
datepart
(mm,
getdate
())
18
select
datepart
(yy,
getDate
())
19
select
datepart
(dd,
getdate
())
20
select
datepart
(dy,
getdate
())
21
select
datepart
(wk,
getdate
())
22
select
datepart
(dw,
getdate
())
23
select
datepart
(qq,
getdate
())
24
select
datepart
(hh,
getdate
())
25
select
datepart
(mi,
getdate
())
26
select
datepart
(ss,
getdate
())
27![None.gif](/Images/OutliningIndicators/None.gif)
28
select
datediff
(dd,
getdate
(),
'
12/25/2006
'
)
--
计算从今天到12/25/2006还有多少天
29
select
datediff
(mm,
getdate
(),
'
12/25/2006
'
)
--
计算从今天到12/25/2006还有多少个月
30
select
datename
(mm,
getdate
())
--
以字符串而不是数字的形式得到今天的月份(07)
31
32
select
dateadd
(dd,
30
,
getdate
())
--
在目前的日期日期上加30天
33
select
dateadd
(mm,
3
,
getdate
())
--
在目前的日期日期上加3个月
34
select
dateadd
(yy,
1
,
getdate
())
--
在目前的日期日期上加1年
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
2
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
3
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
4
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
5
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
6
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
7
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
8
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
9
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
10
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
11
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
12
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
13
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
14
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
15
![ExpandedBlockEnd.gif](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
16
![None.gif](/Images/OutliningIndicators/None.gif)
17
![None.gif](/Images/OutliningIndicators/None.gif)
18
![None.gif](/Images/OutliningIndicators/None.gif)
19
![None.gif](/Images/OutliningIndicators/None.gif)
20
![None.gif](/Images/OutliningIndicators/None.gif)
21
![None.gif](/Images/OutliningIndicators/None.gif)
22
![None.gif](/Images/OutliningIndicators/None.gif)
23
![None.gif](/Images/OutliningIndicators/None.gif)
24
![None.gif](/Images/OutliningIndicators/None.gif)
25
![None.gif](/Images/OutliningIndicators/None.gif)
26
![None.gif](/Images/OutliningIndicators/None.gif)
27
![None.gif](/Images/OutliningIndicators/None.gif)
28
![None.gif](/Images/OutliningIndicators/None.gif)
29
![None.gif](/Images/OutliningIndicators/None.gif)
30
![None.gif](/Images/OutliningIndicators/None.gif)
31
![None.gif](/Images/OutliningIndicators/None.gif)
32
![None.gif](/Images/OutliningIndicators/None.gif)
33
![None.gif](/Images/OutliningIndicators/None.gif)
34
![None.gif](/Images/OutliningIndicators/None.gif)