Yes, you can generally take vitamin D and magnesium together. They're a common pairing, and plenty of products combine them in one capsule or gummy. Most people don't need to space them apart. If you take prescription medication, run your supplement list by a pharmacist.
A common pairing
Taking both at the same meal keeps things simple, and simple is usually the point. The fewer separate moments you have to remember each day, the more likely the habit lasts.
Vitamin D is fat-soluble, so a meal with some fat suits it. Some people prefer magnesium in the evening because they find it relaxing. Either works, so go with whatever you'll remember. There's no single correct clock time. Pick a moment that's already in your day, like breakfast or right after dinner, and let the supplements ride along.
Some people find magnesium on a mostly empty stomach doesn't sit well, so they take it with a meal, either the same one as their vitamin D or a different one. That's about comfort, not a rule. Digestion and schedules vary, so pay attention to what feels right for you over a week or two instead of copying someone else's routine.
Thinking about timing and spacing
A lot of worry about combining supplements comes from medicines that really do need spacing, like certain antibiotics or thyroid medication. Vitamin D and magnesium are more forgiving, which is partly why they're sold together so often. If you're on prescription medication, though, mention your full supplement list at your next pharmacy visit or check-up so nothing gets missed.
If you take more than these two, say a multivitamin, fish oil, or a probiotic, sort them into a morning group and an evening group. Grouping by time of day is easier to keep in your head than five separate times.
Keeping the routine simple
One time or two, a reminder takes the effort out of it. Pillog lets you group doses or set separate times, check them off from the notification, and see your month as a card, all on your phone with no account and no ads. Tie the reminder to something that happens every day anyway, like coffee, brushing your teeth, or walking the dog. That tends to work better than memorizing a clock time.
When you add something new, start small and give it a week or two before judging it. Changing several things at once makes it hard to tell which one caused a problem.
If you take several supplements or any medicines, a pharmacist can confirm sensible combinations and amounts, especially if you have other health conditions or prescriptions. They can also tell you whether a particular form of magnesium or a particular vitamin D dose fits you better, which general advice like this can't do.