In common law countries, the first law allowing affirmation in court was the Quaker Act 1695 . This was limited specifically to Quakers and didn't permit them to give evidence in criminal proceeedings or to serve on juries. The form of the affirmation given is:
I A.B. do declare in the Presence of Almighty God the Witnesse of the
Truth of what I say.
An oath, which is what you make when you "swear" something, is formally speaking a promise made to God upon which you expect others to rely, and is one for of statement that can give rise to a perjury conviction.
An affirmation is a statement that you state is true under penalty of perjury made only to other men and women and not to God. It is preferred by ...
No difference as to the legal effect.
The two versions exist simply to fit religious and secular persons respectively.
I am looking for code, statute, law, or perhaps a written reference to tradition.
Depends on the jurisdiction, but will basically say the same everywhere where the two forms are used.