An answer at answers.com quotes American Heritage Dictionary of Idioms to the effect that to not give someone the time of day means
Ignore someone, refuse to pay the slightest attention to someone, as in He's tried to be friendly but she won't give him the time of day. This expression, first recorded in 1864, alludes to refusing even to answer the question, "What time is it?"
By contrast, an answer at tywkiwdbi.blogspot.com says:
the expression goes far back beyond the time when people wore watches... In Shakespeare's day, the meaning was quite clear. "Good time of day" or "fair time of day" was a salutation just like "good morning" or "good evening"...We no longer greet people by saying "good time of day," but we still use the idea of giving such a greeting as a sign of favorable attention. In other words, refusing to give someone the time of day is thinking so little of him that you would not say hello to him on the street." (credit to Scribal Terror)
If tywkiwdbi and Scribal Terror are right, then the expression is rather older than the AHD Dictionary of Idioms said.
Edit: The BBC Learning English presentation “Not give someone the time of day” says:
Long ago, in Shakespeare's time, the phrase 'good time of day' was a greeting often used. These days we say 'good morning' [or 'good afternoon'] … So to say that you wouldn't give someone the time of day means you wouldn't want to greet them or say hello. So the saying means you refuse to give someone your attention.
As an example of the phrase used in Shakespeare's time, consider King Henry VI, part II, Act III, scene I, as Queen Margaret speaks:
Can you not see? or will ye not observe
The strangeness of his alter'd countenance?
...
We know the time since he was mild and affable,
...
But meet him now, and, be it in the morn,
When every one will give the time of day,
He knits his brow and shows an angry eye,
And passeth by with stiff unbowed knee,
Edit 2: Another example from Shakespeare (as pointed out by ΜετάEd's reference) is from King Richard III, Act I, scene III, when Buckingham says “Good time of day unto your royal grace!”. Note, Shakespeare is believed to have written both plays about 1591; he might or might not have put 16th-century speech into the mouths of 15th-century people. Henry VI was King of England and/or France at various times between 1422 and 1471, and Richard III from 1483 until his demise in 1485.
The word rage comes through French from Latin rabies, "frenzy, rage, madness". The English word apparently went from rage "vehement passion" to the fixed phrase the rage meaning "the latest fad"; then the expression x is the rage was intensified by adding all, similar to the way you can add all to other things, like x is all messed up.
According to the Oxford English Dictionary, the oldest sense of the English word rage as used in the 13th century was "madness; insanity; a fit or access of mania. Obs. exc. poet." (sense 1a).
The sense of "a vehement passion for, desire of, a thing" (sense 7a) was already used by Shakespeare, in it oldest quotation:
1593 Shakes. Lucr. 468 This moves in him more rage...To make the breach.
1671 Milton Samson 836 Call it furious rage To satisfie thy lust. ns iii. 65 The rage which possesses authors to read their writings aloud.
The oldest quotation for the expression (all) the rage (sense 7b), "said of the object of a widespread and usually temporary enthusiasm", is from 1785:
1785 Europ. Mag. VIII. 473 The favourite phrases...The Rage, the Thing, the Twaddle, and the Bore.
1802 Monthly Mag. 1 Oct. 253/1 The rage for the dotting style of engraving...is on the decline.
I'm not entirely sure whether the quotation from 1785 already has x is the rage as a fixed expression; the earliest quotation for that is from 1834:
1834 Lytton Last Days of Pompeii I. i. 173 Sylla is said to have transported to Italy the worship of the Egyptian Isis. It soon became ‘the rage’—and was peculiarly in vogue with the Roman ladies.
At the same time, adding an adverb to intensify the predicate the rage was already in use:
1837 Marryat Perc. Keene ii, In a short time my mother became quite the rage.
And the oldest quotation with all is from 1870, although that may not mean much for its earliest use:
1870 Ld. Malmesbury in Athenæum 4 June 734 In 1776, the game of ‘Commerce’...was ‘all the rage’.
In 1940, the term was apparently thought of as typical of the period after 'the war', which is presumably the First World War:
1940 Graves & Hodge Long Week-End iii. 38 After the war the new fantastic development of Jazz music and the steps that went with it, became, in the comtemporary phrase, ‘all the rage’.
Best Answer
The aphorism was coined by the Dallas Cowboys quarterback, Don Meredith, who later became a sports commentator for the TV show Monday Night Football in 1970.
The 1970 quip soon became Meredith's catchphrase, but it was a modern and comical twist on a much older proverb dating from the 19th century
This proverb is used as a humorous retort to someone expressing a forlorn regret (e.g. if only I had the money...) or an unrealistic and perhaps over optimistic condition (... and if I had the right connections, I could be famous.)
The earliest example I found on Google Books is dated 1845 from The step-mother by George Payne Rainsford James.
@Sven Yargs has discovered an even earlier example, in The New Monthly Magazine and Literary Journal, 1828, from a poem entitled A chapter of Ifs
And finally, printed in 1821, an excerpt translated from a poem entitled Hans Beudix by the German poet Gottfried August Bürger (1747-1794)
The original German poem can be found here: Der Kaiser und der Abt. Maybe someone can confirm if the translation is faithful.
Below is an Ngram comparing the two aphorisms: Don Meredith's “...buts were candy and nuts” (blue line), and the German/British “ands were pots and pans” (red line) side by side in the American English corpus. The time span is between 1968 and 2008. The 1968-72 results for Meredith's coinage are false positives, so it's always wise to take Ngrams with a pinch of salt. No results are displayed for the American rhyme in the British English corpus.
If we expand the time scan between 1835 and 2008 we obtain the following