Either 17 or 30 years from Hamlet's birth to the graveyard scene.

The gravedigger reveals this in his conversation with Hamlet: (5.1.56-100). All the edited texts take their wording from the Second Quarto edition:

Hamlet: …How long hast thou been a grave-maker?

Gravedigger: …I came to’t that day that our last king Hamlet overcame Fortinbras…It was that very day that young Hamlet was born…I have been sexton here man and boy thirty years….this skull hat lien you i’th’earth three-and-twenty years….this same skull, sir, was, sir, Yorick’s skull…

Hamlet: …He hath borne me on his back a thousand times…those lips that I have kissed I know not how oft….

In the First Folio edition, though, the line reads "I have bin sixeteen heere..." (See Chapter One, and many contemporary "sixeteene" usages here.)

In the First Quarto edition, "I have been sexton here man and boy thirty years" is missing, and the gravedigger says instead of 23 years, "here’s a scull hath been here this dozen year." : (Q1: 3361)