It's documented in the early Church councils. These are the earliest occurrences where all the books of the New Testament are declared as Scripture, i.e. God's word. Do you have documentation to the contrary? It's certainly not within Scripture itself.
http://www.abu.nb.ca/courses/NTIntro/2Tim.htm
"Paul wrote 2 Timothy was when he was in prison in Rome for the second time. Unlike his first imprisonment, Paul did not expect to be released from this second Roman imprisonment. (This explains why Paul experienced a mass desertion: his associates were fleeing a dangerous political situation.) The date of the composition of 2 Timothy was during Nero's persecution of the church, c. 64-68. "