You learn them at the same time. Endgames and Openings are not subjects that you can learn overnight. It can take a strong Grandmaster years to master the endgame phase.
It's the same way with openings; simple guidelines and principles should be learned at the beginner, but strong players > 2000-2200 should know heavy opening theory.
So when you first start playing chess, openings and endgames will not be the decisive factor in your games. You should learn the opening principles and guidelines:
don't move the same piece twice unless there is a tactic,
control the central squares,
don't block your c-pawn on c2 in d4 d5 openings, and so on. It even helps to know some simple opening lines, e.g. 1 e4 e5 is the King's pawn game. 1. d4 d5 2.c4 is the Queen's Gambit.
Similarly, start with the simple endgames. Checkmate with King and Rook, checkmate with King and Queen. Also you learn simple pawn endgames, King and Pawn versus King. How do you promote a pawn, if you can? How do you stop the pawn and get a draw, if you can?
Then when you get to about 1500, when you don't make a lot of material blunders, it makes sense to increase your opening knowledge. Learn lines to about 10 moves deep in a few openings that you play, especially the main lines.
At 1500 learn the simple King and Rook and Pawn versus King and Rook endgames, like the Lucena and Philidor positions. It also helps to have some familiarity with Knight, Bishop, and Queen endgames. However theoretical endgames and openings still will not decide your games. Strategy and positional skills, as well as your technique (ability to convert a positional advantage into a point) will.
When you get to a high level, say 1900-2200, your games will be impacted more and more by opening knowledge and endgame skill. Then it makes sense to be an opening and endgame expert.