When national anthem was written?

I hope you mean the US national anthem. If it is, it was written by Francis Scott Key when he was on a british ship overseeing the batlle of Fort McHenry during the beginning of the Revolutionary War. When he wrote this, it was in the form of a poem and he sold it to a local newspaper for a relatively low amount of money and was later cirrculated accross the colonies where it was later given a tune and adopted as the national anthem.