I was on loan with company B for three years of the ten years that I worked for company A.
I worked for company A for ten years and out of those ten years, I worked three of them for company B.
この場合、次のような言い方ができると思います。
ーI was on loan with company B for three years of the ten years that I worked for company A.
「A会社で働いていた10年間のうち、3年間はB会社に出向していた」
to be on loan with ...「…に出向する」を使って表現できます。
for three years of the ten years that ... で「…の10年のうちの3年間」
ーI worked for company A for ten years and out of those ten years, I worked three of them for company B.
「A会社で10年働き、そのうちの3年をB会社で働いた」
out of those ten years で「その10年のうち」
ご参考まで!