DateDiff º¯ÊýÏé½â

DateDiff º¯ÊýÏé½â - ¹ÊÕϽâ´ð - µçÄԽ̳ÌÍø

DateDiff º¯ÊýÏé½â

ÈÕÆÚ£º2007-05-07   ¼ö£º
ÃèÊö
·µ»ØÁ½¸öÈÕÆÚÖ®¼äµÄʱ¼ä¼ä¸ô¡£
Óï·¨
DateDiff(interval, date1, date2 [,firstdayofweek][, firstweekofyear]])
DateDiff º¯ÊýµÄÓï·¨ÓÐÒÔϲÎÊý£º

²ÎÊý ÃèÊö
interval ±ØÑ¡¡£×Ö·û´®±í´ïʽ£¬±íʾÓÃÓÚ¼ÆËã date1 ºÍ date2 Ö®¼äµÄʱ¼ä¼ä¸ô¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ¡°ÉèÖá±²¿·Ö¡£
date1, date2 ±ØÑ¡¡£ÈÕÆÚ±í´ïʽ¡£ÓÃÓÚ¼ÆËãµÄÁ½¸öÈÕÆÚ¡£
firstdayofweek ¿ÉÑ¡¡£Ö¸¶¨ÐÇÆÚÖеÚÒ»ÌìµÄ³£Êý¡£Èç¹ûûÓÐÖ¸¶¨£¬ÔòĬÈÏΪÐÇÆÚÈÕ¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ¡°ÉèÖá±²¿·Ö¡£
firstweekofyear ¿ÉÑ¡¡£Ö¸¶¨Ò»ÄêÖеÚÒ»Öܵij£Êý¡£Èç¹ûûÓÐÖ¸¶¨£¬ÔòĬÈÏΪ 1 Ô 1 ÈÕËùÔÚµÄÐÇÆÚ¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ¡°ÉèÖá±²¿·Ö¡£

ÉèÖÃ
interval ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º
ÉèÖà ÃèÊö
yyyy Äê
q ¼¾¶È
m ÔÂ
y Ò»ÄêµÄÈÕÊý
d ÈÕ
w Ò»ÖܵÄÈÕÊý
ww ÖÜ
h Сʱ
m ·ÖÖÓ
s Ãë

firstdayofweek ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º

³£Êý Öµ ÃèÊö
vbUseSystem 0 ʹÓÃÇøÓòÓïÑÔÖ§³Ö (NLS) API ÉèÖá£
vbSunday 1 ÐÇÆÚÈÕ£¨Ä¬ÈÏ£©
vbMonday 2 ÐÇÆÚÒ»
vbTuesday 3 ÐÇÆÚ¶þ
vbWednesday 4 ÐÇÆÚÈý
vbThursday 5 ÐÇÆÚËÄ
vbFriday 6 ÐÇÆÚÎå
vbSaturday 7 ÐÇÆÚÁù

firstweekofyear ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º

³£Êý Öµ ÃèÊö
vbUseSystem 0 ʹÓÃÇøÓòÓïÑÔÖ§³Ö (NLS) API ÉèÖá£
vbFirstJan1 1 ÓÉ 1 Ô 1 ÈÕËùÔÚµÄÐÇÆÚ¿ªÊ¼£¨Ä¬ÈÏ£©¡£
vbFirstFourDays 2 ÓÉÔÚÐÂÄêÖÐÖÁÉÙÓÐËÄÌìµÄµÚÒ»ÖÜ¿ªÊ¼¡£
vbFirstFullWeek 3 ÓÉÔÚеÄÒ»ÄêÖеÚÒ»¸öÍêÕûµÄÖÜ¿ªÊ¼¡£

˵Ã÷
DateDiff º¯ÊýÓÃÓÚÅжÏÔÚÁ½¸öÈÕÆÚÖ®¼ä´æÔÚµÄÖ¸¶¨Ê±¼ä¼ä¸ôµÄÊýÄ¿¡£ÀýÈç¿ÉÒÔʹÓà DateDiff ¼ÆËãÁ½¸öÈÕÆÚÏà²îµÄÌìÊý£¬»òÕßµ±Ììµ½µ±Äê×îºóÒ»ÌìÖ®¼äµÄÐÇÆÚÊý¡£
Òª¼ÆËã date1 ºÍ date2 Ïà²îµÄÌìÊý£¬¿ÉÒÔʹÓá°Ò»ÄêµÄÈÕÊý¡±£¨¡°y¡±£©»ò¡°ÈÕ¡±£¨¡°d¡±£©¡£µ± interval Ϊ¡°Ò»ÖܵÄÈÕÊý¡±£¨¡°w¡±£©Ê±£¬DateDiff ·µ»ØÁ½¸öÈÕÆÚÖ®¼äµÄÐÇÆÚÊý¡£Èç¹û date1 ÊÇÐÇÆÚÒ»£¬Ôò DateDiff ¼ÆËãµ½ date2 ֮ǰÐÇÆÚÒ»µÄÊýÄ¿¡£´Ë½á¹û°üº¬ date2 ¶ø²»°üº¬ date1¡£Èç¹û interval ÊÇ¡°ÖÜ¡±£¨¡°ww¡±£©£¬Ôò DateDiff º¯Êý·µ»ØÈÕÀú±íÖÐÁ½¸öÈÕÆÚÖ®¼äµÄÐÇÆÚÊý¡£º¯Êý¼ÆËã date1 ºÍ date2 Ö®¼äÐÇÆÚÈÕµÄÊýÄ¿¡£Èç¹û date2 ÊÇÐÇÆÚÈÕ£¬DateDiff ½«¼ÆËã date2£¬µ«¼´Ê¹ date1 ÊÇÐÇÆÚÈÕ£¬Ò²²»»á¼ÆËã date1¡£

Èç¹û date1 ÍíÓÚ date2£¬Ôò DateDiff º¯Êý·µ»Ø¸ºÊý¡£
firstdayofweek ²ÎÊý»á¶ÔʹÓá°w¡±ºÍ¡°ww¡±¼ä¸ô·ûºÅµÄ¼ÆËã²úÉúÓ°Ïì¡£

Èç¹û date1 »ò date2 ÊÇÈÕÆÚÎÄ×Ö£¬ÔòÖ¸¶¨µÄÄê¶È»á³ÉΪÈÕÆڵĹ̶¨²¿·Ö¡£µ«ÊÇÈç¹û date1 »ò date2 ±»°üÀ¨ÔÚÒýºÅ (¡° ¡°) Öв¢ÇÒÊ¡ÂÔÄê·Ý£¬ÔòÔÚ´úÂëÖÐÿ´Î¼ÆËã date1 »ò date2 ±í´ïʽʱ£¬½«²åÈ뵱ǰÄê·Ý¡£ÕâÑù¾Í¿ÉÒÔ±àдÊÊÓÃÓÚ²»Í¬Äê·ÝµÄ³ÌÐò´úÂë¡£

ÔÚ interval Ϊ¡°Äꡱ£¨¡°yyyy¡±£©Ê±£¬±È½Ï 12 Ô 31 ÈÕºÍÀ´ÄêµÄ 1 Ô 1 ÈÕ£¬ËäȻʵ¼ÊÉÏÖ»Ïà²îÒ»Ì죬DateDiff ·µ»Ø 1 ±íʾÏà²îÒ»¸öÄê·Ý¡£
±êÇ©£º