Imam Shafiee rahimahullah said:

أخبرنا خيثمة بن سليمان بن حيدرة القرشي قال: سمعت أبا إسماعيل الترمذي يقول: سمعت البويطي يقول: سئل الشافعي: كم سنك، أو مولدك؟ فقال: ليس من المروءة أن يخبر الرجل بسنه

“al-Booti said: I asked Shaf’iee rahimahullah: How old are you or when were you born? He said: It is not from the manhood for a man to inform [others] of his age”

[Reported by Qaadi Abul-Hasan al-Halabi and the chain is Saheeh]

Translated by

Faisal Ibn Abdul Qaadir Ibn Hassan
Abu Sulaymaan

———-

So it is only a recommendation. As Imam Malik rahimahahullah said:

عبد العزيز الأُوَيْسِيَّ قال: قال رجل لمالك: با أبا عبد الله، كم سنك؟ قال: أقبل على شأنك

Abdul Aziz al-Uwaisi said: a man said to Malik: Oh Aba Abdillah, how old are you? He said: Turn towards your own affair!”

[Reported by Qaadi Abul-Hasan al-Halabi in al-Fawaaid and the chain is Saheeh]

However, it is allowed to inform people of his age and it is not prohibited. Ibn al-Arabi rahimahullah said:

فلا بأس أن يخبر الإنسان بسنه ، كان صغيرا أو كبيرا .

“There is no harm in a person informing a person of his age, whether he is young or old”

[Ahkam ul-Quran]

~ Faisal Ibn Abdul Qaadir Ibn Hassan