TITLE: How do we know that Fermat wrote his famous note in 1637?
QUESTION [55 upvotes]: It is widely stated that Fermat wrote his famous note on sums of powers ("Fermat's last theorem") in, or around, 1637. How do we know the date, if the note was only discovered after his death, in 1665?
My interest in this stems from the fact that if this is true, we can be absolutely certain that whatever proof Fermat in mind was wrong, and he must have noticed (or he would have mentioned it to his correspondents in later years). On the other hand, if the note had been written much later the reasoning would fail. I have used this argument previously in talks for the general public, rather acritically, and I would like to make sure it is sound.

REPLY [5 votes]: There is a relevant piece of information that does not seem to have been mentioned in the other answers so here it is.
Fermat became acquainted with the book by Diophantus by studying in the library of d'Espagnet (father Jean and son Etienne) in Bordeaux around 1629.  This was a period of great creative activity for Fermat, including the invention of the method of adequality (incidentally the term derives from Bachet's latin term adaequalitat which itself derives from Diophantus's Greek parisotes). 
So Fermat may well have written the comment in the  margin of the book Arithmetic by Diophantus as early as 1629.