--ÈÕÆÚת»»²ÎÊý,ÖµµÃÊÕ²Ø
select CONVERT(varchar, getdate(), 120 )2004-09-12 11:06:08
select replace(replace(replace(CONVERT(varchar, getdate(), 120 ),'-',''),' ',''),':','')20040912110608
select CONVERT(varchar(12) , getdate(), 111 )2004/09/12
select CONVERT(varchar(12) , getdate(), 112 )20040912
select CONVERT(varchar(12) , getdate(), 102 )2004.09.12
ÆäËüÎÒ²»³£ÓõÄÈÕÆÚ¸ñʽת»»·½·¨:
select CONVERT(varchar(12) , getdate(), 101 )09/12/2004
select CONVERT(varchar(12) , getdate(), 103 )12/09/2004
select CONVERT(varchar(12) , getdate(), 104 )12.09.2004
select CONVERT(varchar(12) , getdate(), 105 )12-09-2004
select CONVERT(varchar(12) , getdate(), 106 )12 09 2004
select CONVERT(varchar(12) , getdate(), 107 )09 12, 2004
select CONVERT(varchar(12) , getdate(), 108 )11:06:08
select CONVERT(varchar(12) , getdate(), 109 )09 12 2004 1
select CONVERT(varchar(12) , getdate(), 110 )09-12-2004
select CONVERT(varchar(12) , getdate(), 113 )12 09 2004 1
select CONVERT(varchar(12) , getdate(), 114 )11:06:08.177
1. µ±Ç°ÏµÍ³ÈÕÆÚ¡¢Ê±¼ä
select getdate()
2. dateadd ÔÚÏòÖ¸¶¨ÈÕÆÚ¼ÓÉÏÒ»¶Îʱ¼äµÄ»ù´¡ÉÏ£¬·µ»ØÐ嵀 datetime Öµ
ÀýÈ磺ÏòÈÕÆÚ¼ÓÉÏ2Ìì
select dateadd(day,2,'2004-10-15') --·µ»Ø£º2004-10-17 00:00:00.000
3. datediff ·µ»Ø¿çÁ½¸öÖ¸¶¨ÈÕÆÚµÄÈÕÆÚºÍʱ¼ä±ß½çÊý¡£
select datediff(day,'2004-09-01','2004-09-18') --·µ»Ø£º17
4. datepart ·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄÕûÊý¡£
SELECT DATEPART(month, '2004-10-15') --·µ»Ø 10
5. datename ·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄ×Ö·û´®
SELECT datename(weekday, '2004-10-15') --·µ»Ø£ºÐÇÆÚÎå
6. day(), month(),year() --¿ÉÒÔÓëdatepart¶ÔÕÕÒ»ÏÂ
select µ±Ç°ÈÕÆÚ=convert(varchar(10),getdate(),120)
,µ±Ç°Ê±¼ä=convert(varchar(8),getdate(),114)
select datename(dw,'2004-10-15')
select ±¾ÄêµÚ¶àÉÙÖÜ=datename(week,'2004-10-15')
,½ñÌìÊÇÖܼ¸=datename(weekday,'2004-10-15')
º¯Êý ²ÎÊý/¹¦ÄÜ
GetDate( ) ·µ»ØϵͳĿǰµÄÈÕÆÚÓëʱ¼ä
DateDiff (interval,date1,date2) ÒÔinterval Ö¸¶¨µÄ·½Ê½£¬·µ»Ødate2 Óëdate1Á½¸öÈÕÆÚÖ®¼ä
ÍâÀ´¼üÊÇÒ»¸ö(»òÊý¸ö)Ö¸ÏòÁíÍâÒ»¸ö±í¸ñÖ÷¼üµÄÀ¸Î»¡£ÍâÀ´¼üµÄÄ¿µÄÊÇÈ·¶¨×ÊÁϵIJο¼ÍêÕûÐÔ(referential integrity)¡£»»ÑÔÖ®£¬Ö»Óб»×¼ÐíµÄ×ÊÁÏÖµ²Å»á±»´æÈë×ÊÁÏ¿âÄÚ¡£
¾ÙÀýÀ´Ëµ£¬¼ÙÉèÎÒÃÇÓÐÁ½¸ö±í¸ñ£ºÒ»¸ö CUSTOMER ±í¸ñ£¬ÀïÃæ¼Ç¼ÁËËùÓй˿͵Ä×ÊÁÏ£»ÁíÒ»¸ö ORDERS ±í¸ñ£¬ÀïÃæ¼Ç¼ÁËËùÓй˿Ͷ©¹ºµÄ×ÊÁÏ¡£ÔÚÕâÀïµÄÒ»¸öÏÞÖÆ£¬ ......
Êý¾Ý¿â²Ù×÷ÏÖÔÚÊÇÏîÄ¿¿ª·¢µÄ¸ù±¾£¬Ñ§Ï°JavaÊ×ÏÈÓ¦¸Ãѧ»áÔõôÑùÁ¬½ÓÊý¾Ý¿â£¬ÓÃJavaÁ¬½ÓÊý¾Ý¿â¿É²»ÏñÓÃDelphiÕâÀ๤¾ßÄÇÑùÉ輸¸öÊôÐÔ¾ÍOK£¬Ëµ¼òµ¥Ò²¼òµ¥£¬Ëµ¸´ÔÓ£¬ÆäʵҲͦ¸´Ôӵģ¬¶øÇÒºÜÂé·³£¬Èç¹ûÊdzõѧ£¬¸ù±¾²»Äܱ£Ö¤µÚÒ»´Î¾ÍÁ¬½Ó³É¹¦£¬ÏÂÃæÒÔSQL Server 2000ΪÀý£¬ËµËµJavaÁ¬½ÓÊý¾Ý¿âµÄ»ù±¾·½·¨£¬Ò²¼Ç¼һÏÂÐĵá£
1¡¢Ï ......