It is not entirely clear where the psalmist is when he rejoiced.
If the psalm was composed by David, perhaps he wrote it to commemorate the moving of the ark of the covenant into the tabernacle in Jerusalem (2 Samuel 6:1–23).1 Then, David would have been in a town called Kiriath-jearim (2 Samuel 6:2; 1 Chronicles 13:6).
If someone else wrote the psalm, then he could simply be a visitor coming to the city during one of the appointed festivals (Exodus 23:14–17). He could be speaking about either when he decided to leave his home and come to Jerusalem (before he started his journey) or when he arrived at the gates of the city of Jerusalem (at the end of his journey). The reference to feet standing in your gates
suggest that he has just arrived.2
Some have argued that the psalm celebrates a pilgrim’s imminent departure from Jerusalem,3 though this seems very unlikely.
To conclude, the psalmist rejoices when he arrives at the gates of Jerusalem. He has travelled a long way to get here and now he is delighted when someone in the crowd encourages him to go to the house of the Lord.
1 I was glad when they said to me, “Let us go to the house of the LORD!”