Edit 2 In light of the discission at wiki.fr let me add a couple of additional remarks along with a promise that a nonelectronic publication of my views on Fermat will appear within the next two years (if I can find a publisher, that is).
A search in google books for "hanc marginis" and Fermat for the years up to 1900 reveals several hits, none of which claims that the remark was written around 1637; in particular there are no dates given in Fermat's Oeuvres or in Heath's Diophantus. Starting with Dickson's history, this changes dramatically, and nowadays the date 1637 seems to be firmly attached to this entry.
The dating of the entry seems to come from a letter written by Fermat to J. de Sainte-Croix via Mersenne mentioned in Nurdin's answer; this letter is not dated, but since Descartes, in a letter to Mersenne from 1638, refers to a result he credits to Sainte-Croix, but which Fermat claims he has discovered, it is believed that Fermat's letter to Mersenne was written well before that date. The reasons for dating it to September 1636 are not explained in Fermat's Oeuvres.
In this letter, Fermat poses the problem of finding two fourth powers whose sum is a fourth power, and of finding two cubes whose sum is a cube. The reasoning seems to be that in 1636, Fermat had not yet found (or believed to have found) a proof of the general theorem, so the entry must have been written at a later date. Since he did not refer to the general theorem in any of his existant letters, it is also believed that he soon found his mistake, so the entry cannot have been written at a time when Fermat was mature enough to find sufficiently difficult proofs.
Let me also add that the following dates can be deduced from Fermat's letters:
- 1638 Numbers 4n-1 are not sums of two rational squares
- 1640 Fermat's Little Theorem
- 1640 Discovery of infinite descent; used for showing that (1) primes 4n-1 do not divide sums of to squares.
- 1640 Statement of the Two-Squares Theorem
- 1641 - 1645 Proof of (2) FLT for exponent 4
- later: Proof of (3) the Two-Squares Theorem
It is impossible to attach any dates between 1644 and 1654 to Fermat's discoveries since he either wrote hardly any letter in this period, or all of them are lost.
Fermat claimed to have discovered infinite descent in connection with results such as (1), and that he at first could apply it only to negative statements such as (2), whereas it took him a long time until he could use his method for proving positive statements such as (3). Thus the proofs of (1) - (2) - (3) were found in this order.
This means in particular that if Fermat's entry in his Diophantus was written around 1637, then the marvellous proof must have been a proof that does not use infinite descent.
I would also like to remark that the Fermat equation for exponents 3 and 4 had already been studied by Arab mathematicians, such as Al-Khujandi and Al-Khazin, who both attempted proving that there are no solutions. The cubic equation also shows up in problems posed by Frenicle and van Schooten in response to Fermat's challenge to the English mathematicians.