Two distinct points of view are correct in that (1) the grave-digger scene makes Hamlet out to be 30, yet (2) his character suggests someone considerably younger. Is this an inconsistency? The answer lies with original script versions and with the most prominent cast of the play.
It is widely known that the earliest versions of the play did not have the reference to 30 years of age. It is widely believed that the role of Hamlet was played by Richard Burbage, the leading actor of the Lord Chamberlain's Men. And, most likely, he was about thirty and "fat and scant of breath" per Gertrude's comment in V.ii.
Maybe Shakespeare included the dialogue at the later date to accommodate the older actor playing the younger character. This changed the stated age but did not alter the original characterization. As a result we perceive Hamlet as a young man then are shocked to have him defined as being older.
I would count myself amongst the crowd who thinks Hamlet is older. I base my belief on the following conversation that takes place between Hamlet and the 1st Clown, who is the church sexton, a grave-digger, the church cleaner and bell-ringer.
Ham. How long hast thou been
1 Clown. Of all the days i' the year, I came to't that day that our last King Hamlet overcame Fortinbras.
Ham. How long is that since?
1 Clown. Cannot you tell that? every fool can tell that: it was the very day that young Hamlet was born,--he that is mad, and sent into England.
Ham. Ay, marry, why was be sent into England?
1 Clown. Why, because he was mad: he shall recover his wits there; or, if he do not, it's no great matter there.
1 Clown. 'Twill not he seen in him there; there the men are as mad as he.
Ham. How came he mad?
1 Clown. Very strangely, they say.
Ham. How strangely?
1 Clown. Faith, e'en with losing his wits.
Ham. Upon what ground?
1 Clown. Why, here in Denmark: I have been sexton here, man and boy, thirty years.
According to the preceding Act V.i conversation, the grave-digger has been in his occupation since the day Hamlet was born, which he eventually gets around to saying has been thirty years.
Some may argue that Hamlet must be younger since he is in college and he behaves so immaturely, but Gertude and Claudius don't behave much more maturly. Moreover, many people are still pursuing university degrees well into their thirties.
Though scholars debate his age most peg him at around 30. The evidence for their argument rests on factors such as Gertrude and King Hamlet's 30 year marriage.
However, several argue that he is about 20 and base their argument on Yorick's death some twelve years before. These scholars also claim that his maturation during the play is evidence for a younger age, but the "older" camp effectively rebuts by pointing to Claudius and Gertrude, who, though older, are no wiser.
For an interesting debate among Shakespearean scholars about Hamlet's age, visit the shaksper.net link below.
It specifically states in the text in the grave-digger scene in Act 5 that Hamlet is 30. The problem is the trustworthiness of the version of the play that has those lines for the grave-digger. Earlier versions of the play don't give the grave-digger those lines. So do we age hamlet by the original script or by some later revision?
I think I need to counter this and disagree. Its important to know that while the contention exists, 30 years, it is not necessarily 'right'.
I teach script analysis to students, making them understand how to break down a script and look through it for its performative value.
When the question of age came up in Hamlet, my students poured over a lot of arguments that are listed on the Internet, and this is the one that argues for him to be 17. Its a compelling take by Stephen Roth and I think worth pointing out to students.
Another great look at the concept of Time in Shakespeare's plays in general, written by Steve Sohmer, appears in the Early Modern Literary Studies journal and is a lovely reference to how they figured out the time element in the scene where The Ghost of King Hamlet walks the ramparts.