The quote you are talking about is in Act 1 Scene 3 of Hamlet and is actually given to Laertes by Polonius. Laertes has been given permission by King Claudius to return to school in France. In Act 1 Scene 3 Laertes is saying good-bye to his sister Ophelia. Their father Polonius enters and begins to give Laertes some advice. Polonius is known for being a bit long-winded and so his advice is extensive. It includes suggestions that Laertes keep his thoughts to himself, that he not take sides in arguments, and the well-known phrase “neither a borrower nor a lender be.” Polonius’ final piece of advice in his twenty-seven line speech is:
“This above all—to thine own self be true, And it must follow, as the night the day, Thou canst not then be false to any man.”
This is the last advice that Polonius gives to his son. Polonius is killed by Hamlet after Laertes returns to France.