I read the following and was wondering if it was grammatically correct? Can we use this if the person just moved from that place and you run into him in a new place?
For how many days have you been there?
If the person is still in the place referred to as there, then the question How many days have you been there? (present perfect) is the only grammatically correct choice.
If the person is no longer there, then the question must be How many days were you there? (past simple).
Note: how many is sufficient; it doesn't need to be for how many.
The question "For how many days have you been there?" is not quite grammatically correct. "How many days have you been there?" is a more natural phrasing. However in the linked item, the question is redundant with the question after it and should be deleted instead of being rephrased. Note, the item is riddled with clumsy contructions one should avoid, not emulate: "The idea ... pursued her mind" ludicrously personifies idea; "The winds were light ... howling softly" is inconsistent nonsense; "Tom ... was standing in front of his hooded members" is risible. Tense or mood problems include use of "was acting", "would repeat", "would resurface", "would not believe" (and many more such) instead of "acted", "repeated", "resurfaced", "didn't believe".
The phrase is appropriate for the context in the link... because the person was behind the bush several distinct days, not continuously for a period of time.
But for the situation you describe I think it would be better to say "how long have you been there?"