日期:2014-05-18  浏览次数:20489 次

关于 convert datetime 日期样式参数的效果
SQL code
set nocount on
declare @dt datetime
set @dt = getdate()
-- 
-- 2008-04-14 15:47:49.233
-- 
print 'convert(varchar,@dt, 0) : '+ convert(varchar,@dt,0) 
print 'convert(varchar,@dt, 1) : '+ convert(varchar,@dt,1)
print 'convert(varchar,@dt, 2) : '+ convert(varchar,@dt,2)
print 'convert(varchar,@dt, 3) : '+ convert(varchar,@dt,3)
print 'convert(varchar,@dt, 4) : '+ convert(varchar,@dt,4)
print 'convert(varchar,@dt, 5) : '+ convert(varchar,@dt,5)
print 'convert(varchar,@dt, 6) : '+ convert(varchar,@dt,6)
print 'convert(varchar,@dt, 7) : '+ convert(varchar,@dt,7)
print 'convert(varchar,@dt, 8) : '+ convert(varchar,@dt,8)
print 'convert(varchar,@dt, 9) : '+ convert(varchar,@dt,9)
print 'convert(varchar,@dt,10) : '+ convert(varchar,@dt,10) 
print 'convert(varchar,@dt,11) : '+ convert(varchar,@dt,11)
print 'convert(varchar,@dt,12) : '+ convert(varchar,@dt,12)
print 'convert(varchar,@dt,13) : '+ convert(varchar,@dt,13)
print 'convert(varchar,@dt,14) : '+ convert(varchar,@dt,14)
print '15 ~ 19 为无效样式号'
print 'convert(varchar,@dt,20) : '+ convert(varchar,@dt,20) 
print 'convert(varchar,@dt,21) : '+ convert(varchar,@dt,21)
print 'convert(varchar,@dt,22) : '+ convert(varchar,@dt,22)
print 'convert(varchar,@dt,23) : '+ convert(varchar,@dt,23)
print 'convert(varchar,@dt,24) : '+ convert(varchar,@dt,24)
print 'convert(varchar,@dt,25) : '+ convert(varchar,@dt,25)
print '26 ~ 29 为无效样式号'

print 'convert(varchar,@dt,100) : '+ convert(varchar,@dt,100) 
print 'convert(varchar,@dt,101) : '+ convert(varchar,@dt,101)
print 'convert(varchar,@dt,102) : '+ convert(varchar,@dt,102)
print 'convert(varchar,@dt,103) : '+ convert(varchar,@dt,103)
print 'convert(varchar,@dt,104) : '+ convert(varchar,@dt,104)
print 'convert(varchar,@dt,105) : '+ convert(varchar,@dt,105)
print 'convert(varchar,@dt,106) : '+ convert(varchar,@dt,106)
print 'convert(varchar,@dt,107) : '+ convert(varchar,@dt,107)
print 'convert(varchar,@dt,108) : '+ convert(varchar,@dt,108)
print 'convert(varchar,@dt,109) : '+ convert(varchar,@dt,109)
print 'convert(varchar,@dt,110) : '+ convert(varchar,@dt,110) 
print 'convert(varchar,@dt,111) : '+ convert(varchar,@dt,111)
print 'convert(varchar,@dt,112) : '+ convert(varchar,@dt,112)
print 'convert(varchar,@dt,113) : '+ convert(varchar,@dt,113)
print 'convert(varchar,@dt,114) : '+ convert(varchar,@dt,114)
print '115 ~ 119 为无效样式号'
print 'convert(varchar,@dt,120) : '+ convert(varchar,@dt,120) 
print 'convert(varchar,@dt,121) : '+ convert(varchar,@dt,121)
print '122 ~ 129 为无效样式号'

-- convert(varchar,@dt, 0) : 04 14 2008  3:57PM
-- convert(varchar,@dt, 1) : 04/14/08
-- convert(varchar,@dt, 2) : 08.04.14
-- convert(varchar,@dt, 3) : 14/04/08
-- convert(varchar,@dt, 4) : 14.04.08
-- convert(varchar,@dt, 5) : 14-04-08
-- convert(varchar,@dt, 6) : 14 04 08
-- convert(varchar,@dt, 7) : 04 14, 08
-- convert(varchar,@dt, 8) : 15:57:16
-- convert(varchar,@dt, 9) : 04 14 2008  3:57:16:483PM
-- convert(varchar,@dt,10) : 04-14-08
-- convert(varchar,@dt,11) : 08/04/14
-- convert(varchar,@dt,12) : 080414
-- convert(varchar,@dt,13) : 14 04 2008 15:57:16:483
-- convert(varchar,@dt,14) : 15:57:16:483
-- 15 ~ 19 为无效样式号
-- convert(varchar,@dt,20) : 2008-04-14 15:57:16
-- convert(varchar,@dt,21) : 2008-04-14 15:57:16.483
-- convert(varchar,@dt,22) : 04/14/08  3:57:16 PM
-- convert(varchar,@dt,23) : 2008-04-14
-- convert(varchar,@dt,24) : 15:57:16
-- convert(varchar,@dt,25) : 2008-04-14 15:57:16.483
-- 26 ~ 29 为无效样式号
-- convert(varchar,@dt,100) : 04 14 2008  3:57PM
-- convert(varchar,@dt,101) : 04/14/2008
-- convert(varchar,@dt,102) : 2008.04.14
-- convert(varchar,@dt,103) : 14/04/2008
-- convert(varchar,@dt,104) : 14.04.2008
-- convert(varchar,@dt,105) : 14-04-2008
-- convert(varchar,@dt,106) : 14 04 2008
-- convert(varchar,@dt,107) : 04 14, 2008
-- convert(varchar,@dt,108) : 15:57:16
-- convert(varchar,