Basically, the second sentence is wrong. With the perfect tenses, we use "by" and "for" together. Examples: I had studied English for three years by the time I moved to America.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.