sqlÈÕÆÚº¯Êý(ת)
[ 2007-8-23 16:33:00 | By: ²½ ]1.Ò»¸öÔµÚÒ»ÌìµÄ
Select DATEADD(mm, DATEDIFF(mm,0,getdate()), 0)
2.±¾ÖܵÄÐÇÆÚÒ»
Select DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)
3.Ò»ÄêµÄµÚÒ»Ìì
Select DATEADD(yy, DATEDIFF(yy,0,getdate()), 0)
4.¼¾¶ÈµÄµÚÒ»Ìì
Select DATEADD(qq, DATEDIFF(qq,0,getdate()), 0)
5.µ±ÌìµÄ°ëÒ¹
Select DATEADD(dd, DATEDIFF(dd,0,getdate()), 0)
6.ÉϸöÔµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(mm, DATEDIFF(mm,0,getdate()), 0))
7.È¥ÄêµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0))
8.±¾ÔµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
9.±¾ÄêµÄ×îºóÒ»Ìì
Select dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate())+1, 0))
10.±¾ÔµĵÚÒ»¸öÐÇÆÚÒ»
select DATEADD(wk, DATEDIFF(wk,0,dateadd(dd,6-datepart(day,getdate()),getdate())), 0)
·µ»Øµ±Ç°ÈÕÆÚºÍʱ¼ä
ͨ¹ýº¯ÊýGETDATE£¨£©£¬Äã¿ÉÒÔ»ñµÃµ±Ç°µÄÈÕÆÚºÍʱ¼ä¡£º¯ÊýGETDATE£¨£©¿ÉÒÔÓÃÀ´×÷ΪDATEDIMEÐÍ×ֶεÄȱʡֵ¡£Õâ¶Ô²åÈë¼Ç¼ʱ±£´æµ±Ê±µÄ
ʱ¼äÊÇÓÐÓõġ£Òª½¨Á¢Ò»¸ö±í£¬ÆäÖеļǼ°üº¬Óе±Ç°µÄÈÕÆÚºÍʱ¼ä£¬¿ÉÒÔÌí¼ÓÒ»¸öDATETIMEÐÍ×ֶΣ¬Ö¸¶¨ÆäȱʡֵΪº¯ÊýGETDATE£¨£©µÄ·µ»Ø
Öµ£¬¾ÍÏóÕâÑù£º
Create TABLE site_log (
username VARCHAR(40)£¬
useractivity VARCHAR(100)£¬
entrydate DATETIME DEFAULT GETDATE())
ת»»ÈÕÆÚºÍʱ¼ä
º¯ÊýGETDATE£¨£©µÄ·µ»ØÖµÔÚÏÔʾʱֻÏÔʾµ½Ã롣ʵ¼ÊÉÏ£¬SQL SeverÄÚ²¿Ê±¼ä¿ÉÒÔ¾«È·µ½ºÁÃ뼶£¨È·ÇеØ˵£¬¿ÉÒÔ¾«È·µ½3.33ºÁÃ룩¡£
ÒªµÃµ½²»Í¬¸ñʽµÄÈÕÆÚºÍʱ¼ä£¬ÄãÐèҪʹÓú¯ÊýCONVERT£¨£©¡£ÀýÈ磬µ±ÏÂÃæµÄÕâ¸öÓï¾äÖ´ÐÐʱ£¬ÏÔʾµÄʱ¼ä½«°üÀ¨ºÁÃ룺
Select CONVERT(VARCHAR(30)£¬GETDATE()£¬9)
×¢ÒâÀý×ÓÖÐÊý×Ö9µÄʹÓá£Õâ¸öÊý×ÖÖ¸Ã÷ÁËÔÚÏÔʾÈÕÆÚºÍʱ¼äʱʹÓÃÄÄÖÖÈÕÆÚºÍʱ¼ä¸ñʽ¡£µ±Õâ¸öÓï¾äÖ´ÐÐʱ£¬½«ÏÔʾÈçϵÄÈÕÆÚºÍʱ¼ä£º
Nov 30 1997 3:29:55:170AM
(1 row(s) affected)
ת»»ÈÕÆÚºÍʱ¼ä
º¯ÊýGETDATE£¨£©µÄ·µ»ØÖµÔÚÏÔʾʱֻÏÔʾµ½Ã롣ʵ¼ÊÉÏ£¬SQL SeverÄÚ²¿Ê±¼ä¿ÉÒÔ¾«È·µ½ºÁÃ뼶£¨È·ÇеØ˵£¬¿ÉÒÔ¾«È·µ½3.33ºÁÃ룩¡£
ÒªµÃµ½²»Í¬¸ñʽµÄÈÕÆÚºÍʱ¼ä£¬ÄãÐèҪʹÓú¯ÊýCONVERT£¨£©¡£ÀýÈ磬µ±ÏÂÃæµÄÕâ¸öÓï¾äÖ´ÐÐʱ£¬ÏÔʾµÄʱ¼ä½«°üÀ¨ºÁÃ룺
Select CONVERT(VARCHAR(30)£¬GETDATE()£¬9)
×¢ÒâÀý×ÓÖÐÊý×Ö9µÄʹÓá£Õâ¸öÊý