Both sentences are correct and mean the same thing. However, the second sentence would sound better if you changed it around a little to: ""How long were you married for?" In English, always start questions with the question word. Also, in English, it is possible to end a sentence with a preposition (for, of, in, at etc.) but only if the meaning is obvious.