How/when did people before modern times start knowing what year they were living in and when did it start getting written down, for instance, how did people from the year 1066 (or any other year) know to write that year on documents and such?

by ExecuteOrder_69

Forgive me if this has been asked before!

ConteCorvo

Even before the Middle Ages, both in Roman and Greek antiquity, calendar systems were in place as to be able to recall which year was the current one and when a given event happened in the past. In the Roman case we know of both the list of consuls (fasti consulares) which were elected for a given year and the Ab Urbe Condita ("From the founding of the City") system, which counted years starting with the mythical founding of Rome set at 753 BC. The Greeks had used the Olympic games as a widespread calendar system, given their fixed occurrance every four years. This was employed alongside with another widespread custom, the lists of archons, mentioning which ones were the "eponymous archons" (the magistrates whose names would be set at the beginning of these lists, "naming" the year") elected in that year.
There is consensus that the lists of consuls might have been influenced by the lists of archons.

In the transition years between the fall of Rome and the consolidation of the post-Roman or barbaric kingdoms (V-VIII centuries AD), counting the years since the birth of Christ was not a commonplace method. Around the VI century a monk, Dionysius the Humble (Dionysius Exiguus) made a huge calculation effort to unify the occurrences of Easter days across the numerous Christian traditions between the Western and Eastern churches, inventing the Anno Domini system starting with the Julian calendar and the consular lists. In fact, he calculated that Jesus was born on 25th of December 753 Ab Urbe Condita, what would be known as the year 0. He's likely to have made some mistakes, since some experts point at 749 AUC to be a more exact date.

During the whole of the Medieval period, to know the current date would be a diverse matter, starting with your occupation. A farmer or a craftsman would likely have had little interested in knowind which year it was, but he might have been rather keen on what month or day since it was paramount to know when Easter was arriving, if a given saint's day was ahead or how many days of Lent were expected. A scholar or jurist would have been much more keen on the exact date, especially the latter. Already in Lombard times, notary instruments were written out with clear indications about the day, the month and the year the matter discussed in the document had been resolved.
If someone needed to recall what year it was, say, a judge, he could have checked his own archive or his most trusted notary's archive for a recent document to read its content and time (or, most likely, the apprentice notary would have been charged to do this). Auxiliary to this, there was an additional system in place, called Indiction.
These were cycles of time, usually of 15 years each, with different starting and ending points, quite varied on cultures (for example, the Byzantine Indiction, used both in Greece and Southern Italy up until the Modern Age, starts the year September 1st and ends it August 31st. The Incarnation Indiction, used in Florentine areas and based on Dionysus' calculation, place the year's beginning and end on March 25th (the day the Virgin Mary had her pregnancy announced to her).

The AD system and the Indiction were used often in conjunction, in some cases one replace the other. It's worth noting that the Indiction was especially used a fiscal calendar to keep track of payments and other administrative matters. On top of this, at times, it could also be added the year of reign of the current sovereign (i.e. "Anno Domini 1464, 12th indiction, third year of the reign of our Most Illustrious King Ferdinand of Aragon, king of Naples").

I hope this answer helps your inquiry.