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

In the accepted text, based on in the Second Quarto and First Folio editions, the gravedigger reveals this in his conversation with Hamlet: (5.1.56-100)

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 Quarto edition, though, "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)