Search code examples
exceldateexcel-formulams-office

Subtracting two dates in Excel


I would like to subtract two dates, the birth date, and the study date, and store the difference in terms of months. The DICOM entries have a weird format for the birth date (e.g.,19760404) and study date (e.g., 19940211). These entries are in the YYYYMMDD sequence. How do I compute the difference between these two values in terms of months?


Solution

  • What about this,

    enter image description here

    • Formula used in cell C2

    =INT(YEARFRAC((TEXT(A2,"0000\/00\/00")+0),(TEXT(B2,"0000\/00\/00")+0))*12)
    

    Or, using DATEDIF()

    • Formula used in cell D2

    =DATEDIF((TEXT(A2,"0000\/00\/00")+0),(TEXT(B2,"0000\/00\/00")+0),"M")