shiva
shiva

Reputation: 1189

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?

Upvotes: 1

Views: 159

Answers (2)

Mayukh Bhattacharya
Mayukh Bhattacharya

Reputation: 27438

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

Upvotes: 2

cybernetic.nomad
cybernetic.nomad

Reputation: 6418

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

Upvotes: 1

Related Questions