That is a great question! Unfortunately, it isn’t as complex as you may think it is. It has a simple answer. You just have to pace yourself.
That means when you are learning to code, learn small sections at a time and make sure you take 2 days off during the week. Treat it like a full time job. Yes, you can work “overtime” when learning and during 5 days a week go crazy but during the other 2 days, don’t code anything at all. That gives your brain, body, etc. time to relax and unwind so you don’t get burnt out.
If you have tried this and are still feeling burnt out, then take 3 days off or 4 days off. Yes, it may take you longer to learn how to code and that is okay. There is no “deadline” for when you need to learn how to code by. Also, you don’t “need” to learn how to code. It is a “want” meaning you can get yourself to that point in your own time.
I hope this helps!