This is terrible advice. While I understand the author's desire to encourage people to not give up, if you've been working on a problem for several hours without a solution, it's time to do something else and let your subconscious churn on it.
Dont stay up late. You will feel worse the next day. Get up early instead.