Please can you confirm that there is this hadith ( ≈ wording)?
Someone who lives 40 * in a country / among a people will be like them.
* this was unspecified, could be 40 months / years?
I am not aware of any such hadith. There are several hadiths generally prohibiting residence among non-Muslims but they are not time-specific, such as:
من جامع المشرك وسكن معه فهو مثله
Whoever lives in harmony with pagans and dwells with them is certainly identical to them.
أنا بريء من كل مسلم يقيم بين أظهر المشركين
I am innocent of every Muslim who lives among the idolaters.
من كثّر سواد قوم فهو منهم
Whoever contributes to the aggregate of a people is certainly one of them.
Of note is the related scholarly rule in hadith science:
وَالنِّسْبَة إِلَى المولد حَقِيقَة، وَإِلَى المنشأ والتوطن مجَاز. (ابْن الْمُبَارك) : أَقَله أَربع سِنِين.
which means: “One’s affiliation is literally to the place of birth and figuratively to the place of rearing and immigration. Ibn al-Mubarak said: ‘The latter is four years minimum.'”
See al-Ja`bari in Rusum al-Tahdith fi `Ulum al-Hadith, al-Nawawi in al-Taqrib wal-Taysir, al-Tibi in al-Khulasa fi `Ulum al-Hadith, Ibn Jama`a in al-Manhal al-Rawiy fi Mukhtasar `Ulum al-Hadith, Ibn al-Mulaqqin in al-Muqni` fi `Ulum al-Hadith, al-Sakhawi in Fath al-Mughith, al-Suyuti in Tadrib al-Rawi and others.
Hajj Gibril Haddad