ÃèÊö ·µ»ØÁ½¸öÈÕÆÚÖ®¼äµÄʱ¼ä¼ä¸ô¡£ Óï·¨ DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]]) DateDiff º¯ÊýµÄÓï·¨ÓÐÒÔϲÎÊý£º ²ÎÊý ÃèÊö interval ±ØÑ¡¡£String expression ±íʾÓÃÓÚ¼ÆËã date1 ºÍ date2 Ö®¼äµÄʱ¼ä¼ä¸ô¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ“ÉèÖÔ²¿·Ö¡£ date1, date2 ±ØÑ¡¡£ÈÕÆÚ±í´ïʽ¡£ÓÃÓÚ¼ÆËãµÄÁ½¸öÈÕÆÚ¡£ firstdayofweek ¿ÉÑ¡¡£Ö¸¶¨ÐÇÆÚÖеÚÒ»ÌìµÄ³£Êý¡£Èç¹ûûÓÐÖ¸¶¨£¬ÔòĬÈÏΪÐÇÆÚÈÕ¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ“ÉèÖÔ²¿·Ö¡£ firstweekofyear ¿ÉÑ¡¡£Ö¸¶¨Ò»ÄêÖеÚÒ»Öܵij£Êý¡£Èç¹ûûÓÐÖ¸¶¨£¬ÔòĬÈÏΪ 1 Ô 1 ÈÕËùÔÚµÄÐÇÆÚ¡£ÓйØÊýÖµ£¬Çë²ÎÔÄ“ÉèÖÔ²¿·Ö¡£ ÉèÖà interval ²ÎÊý¿ÉÒÔÓÐÒÔÏÂÖµ£º ÉèÖà ÃèÊö yyyy Äê q ¼¾¶È n Ô 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 ±íʾÏà²îÒ»¸öÄê·Ý¡£ ÏÂÃæµÄʾÀýÀûÓà DateDiff º¯ÊýÏÔʾ½ñÌìÓë¸ø¶¨ÈÕÆÚÖ®¼ä¼ä¸ôÌìÊý: Function DiffADate(theDate) DiffADate = "´Óµ±Ì쿪ʼµÄÌìÊý:" & DateDiff("d", Now, theDate) End Function (ÔðÈα༣ºadmin) |