how long did hagia sophia take to build?

These two sites should be of help with that question.

http://en.wikipedia.org/wiki/Hagia_Sophia
http://www.sacred-destinations.com/turkey/istanbul-hagia-sophia.htm

http://www.turizm.net/turkey/history/hagiasophia.html

Excerpt:

This construction of the second Hagia Sophia was started in 532 by the order of the Emperor Justinian and was built over the ruins of an earlier structure. Materials were brought from Ephesus, Athens, Rome, and Delphi and were used in the construction of this magnificent building. The church was opened for worship five years later, in 537.

The Hagia Sophia, located in Istanbul, Turkey, took several years to build. Construction of the original structure began in the year 532 CE and was completed in 537 CE, making it a total of five years to build. However, it is important to note that the Hagia Sophia has undergone several renovations and modifications over the centuries, which may have extended the overall construction timeline.