Home > Net >  Subtracting two dates in Excel
Subtracting two dates in Excel

Time:10-26

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?

CodePudding user response:

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")

CodePudding user response:

Convert the strings to dates, then substract one from the other. Assuming the two dates are in A1 and B1 you would get something like this:

=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))-DATE(LEFT(B1,4),MID(B1,5,2),RIGHT(B1,2))
  • Related