He joined the prayer behind the imam but his intention was different from that of the imam
Question

if at the time of asr with a jamaa'ah a person enters the salah thinking that he's praying dhuhr and during the salah he realizes that its actually asr, what should he do when his niyaa(intention) changes during that prayer.  Does he have to cut the prayer at that point and make a new takbeeratul ihram?
Praise be to Allah.This question refers to one of two scenarios: 
The first scenario is where the questioner has prayed Zuhr then he joins them to pray ‘Asr with the intention of praying Zuhr because he has forgotten, then during the prayer he remembers that this prayer is ‘Asr. In this case it is not correct for him to change his intention by now intending to pray ‘Asr. Rather he should stop praying, then say Allahu akbar and re-join the prayer with the imam, with the intention of praying ‘Asr. That is because the intention is a condition of the prayer’s validity. The basis for this (i.e., for the intention being required for prayer) is that whoever changes his intention for one specific prayer, whether it is fard (obligatory) or naafil (supererogatory), to another specific prayer, the prayer he originally intended to pray becomes invalid and cannot be counted as the other prayer for which he changed his intention. Rather he should stop praying the prayer that he initially intended, then say takbeerat al-ihram (say “Allahu akbar” to start a prayer) with the intention to pray the other prayer. And Allah knows best. See al-Sharh al-Mumti’, 2/296. 
The second scenario is where he has not prayed Zuhr at all, and he comes to the mosque and finds them praying ‘Asr. 
Shaykh Ibn Baaz (may Allah have mercy on him) was asked: if a person has missed a prayer, such as Zuhr, then he remembers it when the iqaamah for ‘Asr prayer has been given, what should he do? He replied: What is prescribed for such a person is that he should pray with the current jamaa’ah (congregation), but with the intention of praying Zuhr, then he should pray ‘Asr after that, because it is obligatory to pray the prayers in the correct order, and that obligation is not to be ignored for fear of missing the prayer in congregation. 
Elsewhere, he said: the difference of intention between the imam and the one who is praying behind him does not matter, according to the correct scholarly view. 
And Allah knows best. 
Fataawa al-Shaykh Ibn Baaz (may Allah have mercy on him), vol 12, p. 190-191.