If you are going to the Altar of the Moone in Pokemon Moon it has to be Daytime in your game. If you are Going to the Altar of the Sunne in Pokemon Sun then it has to be nighttime in your Game.
Since you have Moon, it has to be Daytime in that game in order to go to the Other world and get the Secret Cosmog. NOTE: you have to have Lunala in your party when you go to The Altar of the Moone.
Hope this helps :)