What happens is the plants absorb the carbon dioxide in the air which we produce by breathing in oxygen and breathing out carbon dioxide. They then combine the carbon dioxide, water, and sunlight because most plants cannot live with sunlight, to create glucose which is the second formula you have in your question.