When asks a question that is looking for a defined time in the past.
Q: When did it start raining?
A: It started raining at 10 o'clock this morning.
Q: When did you get married?
A: We got married in 2004.
Q: When did you buy those jeans?
A: I bought these jeans last week.
How long asks a question to find out the length of time the event has been happening for.
Q: How long has it been raining?
A: It has been raining for three hours.
Q: How long have you been married?
A: We have been married since 2004.
Q: How long have you had those jeans?
A: I have had these jeans for a week.
Note: When we answer a question that asks how long we can answer it using for or since.
Looking at the second example we can say:
We have been married since 2004
We have been married for seventeen years.
Remember that for and since cannot be used interchangeably so check our this blog post for more information on their usage:
Starting a question with when means we use the present simple tense.
Starting a question with how long means we use the present perfect tense.