The First and Second Letter to Timothy 1 and 2 Timothy are letters written by Paul not to a particular church, but to his apprentice, Timothy. Most scholars who hold to Pauline authorship of 1 and 2 Timothy date them close together near the end of Paul's life. However, the analysis here separates them by a considerable time, with 2 Timothy near the end of Paul's life and 1 Timothy much earlier.
There is no hint in 1 Timothy that Paul is in prison. In other letters, where Paul is in prison, he says so or alludes to it multiple times, so this fact alone tends to date 1 Timothy prior to Paul's imprisonment in Caesarea in 57 A.D. Paul says he urged Timothy to stay at Ephesus while he went to Macedonia (1 Tim 1:3). These are events from Paul's third missionary journey (Acts 20:1). This provides the reason for the letter, instructing Timothy in how to manage the church in Paul's absence. Timothy is still quite young (1 Tim 4:11-15). Timothy would have needed this letter toward the beginning of his time in Ephesus, not years later, so it is best to assume that Paul wrote it very shortly after his departure. Since Paul spent three years in Ephesus (Acts 20:31) and his departure was toward the end of his third missionary journey, the best date for 1 Timothy would be around 56 or early 57 A.D.
2 Timothy is written by Paul from Prison, in difficult circumstances (2 Tim 1:8, 1:12, 1:16, 2:3, 2:9). Unlike Paul's other prison letters, we can state with some confidence that this was not prison in Caesarea, but in Rome, since Onesiphorus found him there in 2 Tim 1:17.
2 Timothy was definitely written after the other prison letters of Colossians and Ephesians. Luke and Demas are with Paul in Col 4:14, but in 2 Tim 4:10-11 Demas "has forsaken" Paul and only Luke remains with him. Paul says in the past tense in 2 Tim 4:12 that "Tychicus I have sent to Ephesus", while in Col 4:7 and Eph 6:21-22 Tychicus is being sent.
Paul's outlook for his own life has darkened considerably from his earlier prison letters, and he doesn't expect to live much longer (2 Tim 4:6-8). This may have been due to an unfavorable first legal hearing (2 Tim 4:16) occurring in between the earlier prison letters and this one. These circumstances can only have come about after the upbeat end of the account in the book of Acts. Therefore, we should consider 2 Timothy to be chronologically the last letter of Paul that appears in the Bible, written around 63 A.D.