I could not find any information that tells exactly how long a person would have to have an STD for it to cause infertility. The general idea is that you would have to have an untreated STD for a long time before it would affect fertility. If you're worried about either of those diseases, get tested ASAP. Is there any reason why you specifically think that your infertility is caused by an STD as opposed to something else?