This is the number of years that someone has lived, or that something has existed.

(What is the part of speech of 'that'? Is 'that' a relative pronoun or a relative adverb? Can we use 'when' instead of 'that' in the sentence?)

In that sentence, "that" is being used as a relative pronoun, referring to "years" as its antecedent.

http://dictionary.reference.com/browse/that?&qsrc=

If you use "when" instead of "that," you change the meaning of the sentences.