My question is if a person did the niyat for first day of Ramadhan and later he came to know that it is last day of shaaban (29 or 30) then what he should do in this case and what about that day of fasting”

In this situation he suppose to made the Niyat of the qadha if there was any if there is no qadha then make the Niyat of qurbat . If he was not aware of the masala In’Sha’Allah Allah will reward him for his effort but not transfer to the qadha because he has not intended for the qadha.