สูตร DateDif ควรหรือไม่ควรใช้กันแน่

หลายคนอยากจะหาระยะเวลาจากวันนั้นถึงวันนี้ว่าเป็นกี่ปี กี่เดือน กี่วัน สูตร DateDif เป็นสูตรที่แนะนำให้ใช้กัน ซึ่งผมเองจะสอนสูตรนี้เพื่อหลีกเลี่ยงไม่ให้ใช้หรือถ้าอยากจะใช้ก็ควรใช้อย่างระมัดระวัง อย่านำไปใช้กับงานสำคัญ

อ่านคำแนะนำของผมได้จาก
https://www.excelexperttraining.com/home/online/articles/general/258-datedif-false-answer

Microsoft แนะนำว่า The “MD” argument may result in a negative number, a zero, or an inaccurate result.

https://support.microsoft.com/en-us/office/datedif-function-25dba1a4-2812-480b-84dd-8b32a451b35c

มาดูคำแนะนำจากคนเก่ง Excel

Is DATEDIF a safe function?

I know this is a bit strange but many Excel Gurus say that it’s not good to use DATEDIF in your important workbooks. As this is an undocumented function and going forward there may be a chance that Microsoft may remove support for this function.

https://www.exceltrick.com/formulas_macros/excel-datedif-function/

==========================

An informal survey of fellow MVPs shows the above formula works correctly in the initial release of XL2007 and its SP1, but does not work correctly in SP2; hence, it appears to be broken at that level. The problem is that the extent of the breakage is unknown (and probably indeterminable). In addition, I would say, being an undocumented (and, thus, probably an unsupported) function, the odds of Microsoft spending the time to search down and fix whatever broke is slim. In addition, again because it is probably unsupported, the extent of any future breakage in the function due to other code change Microsoft makes elsewhere in Excel is unknowable… something that works today may not work tomorrow and Microsoft will probably never fix it…..

Personally, I am still holding firm to my recommendation that DATEDIF not be used anymore (for the reasons I gave in the paragraph before my ADDITIONAL FOLLOW-UP #1).

https://excelfox.com/forum/showthread.php/321-Recommendation-Do-not-use-the-undocumented-DATEDIF-function

คำแนะนำสุดท้ายนี้ น่าสนใจมากเพราะเป็นคำเตือนให้เราระวังด้วยว่า Excel ต่างรุ่นกัน อาจได้คำตอบต่างกันได้ด้วย


 

หากจะคิดสูตรใหม่ขึ้นมาใช้ ต้องกำหนดหลักการนับให้ชัดเจนก่อน

จะนับเป็น 1 ปี เมื่อใด
1/10/1996 – 1/10/1997 นับวันชนวัน
หรือ
1/10/1996 – 2/10/1997 นับถึงวันถัดไปจึงครบปี

จะนับเป็น 1 ปี 1 เดือนเมื่อใด
31/1/1996 – 28/2/1997 นับวันสิ้นเดือนชนกัน
หรือ
31/1/1996 – 29/2/1997 สมมตว่ากพมี 29 วัน
หรือ
31/1/1996 – 1/3/1997 นับเดือนกพเต็ม 1 เดือน
หรือ
31/1/1996 – 2/3/1997 ถ้ากพมี 29 วัน ต้องเพิ่มไปอีก 2 วัน
หรือ
31/1/1996 – 3/3/1997 นับถึงวันถัดไป

จะนับเป็น 1 วันเมื่อใด
1/10/1996 – 1/10/1996
หรือ
1/10/1996 – 2/10/1996

เรื่องหลักการนับนี่แหละครับที่สูตรลัดใดๆ อาจหาไม่ตรงกับหลักนับของผู้ใช้งานแต่ละคนแต่ละบริษัท