I found Google Books search results for several seemingly related forms of the phrase in question. They are, in chronological order of appearance, "six ways for Sunday," "six ways from Sunday," "forty ways from Sunday," and ""six ways to Sunday."
'Six ways for Sunday'
Here are the first five instances of "six ways for Sunday" in the search results:
From "Morning Visits," in The American Monthly Magazine (1824):
Mrs. D[rugget, to her husband]. Well, but my dear, we must indulge the girls now and then; I'm sure you can afford it very well. For my part, if it hadn't been for that awkward Phil. Dowlas, that stumbled agen Bill's elbow, and knocked the things off of the waiter, I think it would have been a very pleasant time.
Car[oline]. Yes, the careless, good for nothing feller, he's always looking about six ways for Sunday, when he's walking—I wish he'd stay at home and his sisters too.
From "An Original Character" in The Family Magazine, Volume 8 (1840):
Near the road was a tall, raw-boned, overgrown, lantern-jawed boy, probably seventeen years of age, digging potatoes. He was a curious figure to behold. What was lacking in the length of his tow breeches was amply made up for behind; his suspenders appeared to be composed of birch bark, grape vine and sheepskin; and as for his hat which was of dingy white felt—poor thing! It had once evidently seen better days, but now, alas! It was only the shadow of its glory. Whether the tempests of time had beaten the top in, or the lad's expanding genius had burst it out, was difficult to tell; at any rate it was missing—and through the aperture red hairs in abundance stood six ways for Sunday.
From T.C. Halliburton, "The Season Ticket" in Dublin University Magazine (1860):
I sat up late that night at Springfield, with some patriots and heroes of Bunker Hill, and the battle of Mud Creek, to hear the result of the election for President, for we were all for John Adams. It was eleven o'clock at night when the word came; we were all excited, drinking success to Adams, and confusion to Jefferson, glory to the nation, prosperity to religion, perdition to free thinkers, infidels, and southern candidates, with other patriotic toasts, when in rushed Deacon Properjohn, his eyes strain six ways for Sunday, his hair blowin about like a head of broom corn, and his breath a'most gone. "Hallo," sais I, "Deacon, what is the matter of you? Who is dead, and what I to pay now?" "Why," sais he, striking the table with his fist, a blow that made all the glasses jingle again, "I'll be darned if that old unbelievin sinner Jefferson hain't beat Adams by a majority of one," and he burst into tears.
From "Blue Eyes and Battlewick" in The Southern Literary Messenger (1860):
[A description of the Sliding Carnival in Hobgoblinopolis:] "Hello! Hello! what's that? Somebody is tossed high in air, as from the horn of a mad bull; the sled is keel upwards, the rider is on his back, kicking his heels at the sky as if he thought some of the heavenly bodies might be boot-jacks. He is in the middle of the track and everybody runs into him—everybody is upset, and everybody is kicking more heels at the heavenly boot-jacks. It id a ridiculous spectacle, and suggests the idea of a kind of strange black wheel—all hubs and spokes, and no tires—revolving six ways for Sunday.
From Godey's Magazine (1864) [combined snippets]:
I wish you could have seen John Henry's face as his glance "took her in." As near as I can describe it the expression thereof was a luminous representation of that extraordinary physiognomical phenomenon known as "looking six ways for Sunday." With regard to Miss Bessy's portraiture, I can only state my conviction that, although at some remote period she had undoubtedly been young, no memory of man could have recalled an epoch in which she had claimed, of right, the homage that valor owes to beauty.
'Six ways from Sunday'
Here are the two earliest instances of "six ways from Sunday" in Google Books search results:
From Lynn Roby Meekins, "The Assistant Boss," in The Saturday Evening Post (April 8, 1899):
She folded her hands in a pose of feminine helplessness and dependence, and leaning forward a bit imploringly, looked the politician straight in the eyes, and asked in tones that would have moved a saint or converted an infidel: "Mr. Stack, may I depend on you?"
Stack afterward told of it. "When she did that," he said, "knocked me six ways from Sunday. Those eyes of hers looked right down into my soul, and before I knew what I was doing I was on my feet, saying with a bow, 'You can ma'am, to the end of time and the other side of eternity,' and what's more I'm going to do it."
From The American Flint, Volume 18 (1926) [snippet, reported in the search result summary page but not matched in the resulting snippet text]:
The glass manufacturers have it all over this man Ford six ways from Sunday. I know a lot of glassworkers who only work two or three days a week.
'Forty ways from Sunday'
Here are the three earliest occurrences of "forty ways from Sunday" in Google Books search results:
From Richard Croker, "The Best Story I Ever Heard," in Masterpieces of Wit and Humor (1903):
This man [a politico from the Bowery in Manhattan, invited to attend a gala event hosted by the Tammany society] at first decided that he would not attend the ball, as he objected to appearing in full dress, but at the last moment he changed his mind and rented a dress suit from a costumer on lower Broadway. It fit him forty ways from Sunday. The trousers were too large, the coat was too small, and altogether he looked like a section of liverwurst in a misfit casing.
From Mrs. Hugh Fraser, Italian Yesterdays, Volume 2 (1913)
Since I have seen it at close quarters, I have often thought of the contrast presented by that handful of North Country shepherds and their descendants, in the Falklands, so proud of doing their best with the best they could get, pleased with their drizzly climate (it rains two hundred and fifty days in the year), because it is so English, proud of their thriving little country, sending out their pelts and mutton by the once-a-month steamer, actually growing their pelargoniums and fuchsias in the open air, and so furiously interested in their miniature politics that the Government and the Opposition are ready to knock each other forty ways from Sunday every time they meet!
From The Typographical Journal (February 1915)
[Galt, Ontario] Business, as usual, is rotten. The Reporter news side has been on a forty-one-hour-a-week schedule for three months, and not much prospect of relief for some time to come. The present trade depression has the "slump" of '07 skinned forty ways from Sunday.
'Six ways to Sunday'
The earliest instance of the phrase "six ways to Sunday" in Google Books search results appears to be this one from The Dairy (1937?) [snippet]:
There are, no doubt, many dairymen who know the food retailing business backwards and forwards and six ways to Sunday, but these are men who, at some time in their busy career, have been in the provisions business.
And the next-earliest instance in the search results is from Myra Page, The Sun in Our Blood (1950):
John laughed outright. "Dol you make a poor liar." From his shirt front he drew out his Bobtail envelope and handed it to me, its flap still unbroken. "Here you are, girl. And stretch it six ways to Sunday."
From these results, it appears that the meanings "completely" and "thoroughly" arrived somewhat later, and that the earliest meaning (and the only one during most or all of the nineteenth century) was "every which way" or, as Wikipedia and Wictionary have it, "in every way imaginable."
EDIT: One additional note: Eric Partridge, in A Dictionary of Slang and Unconventional English, Fifth Edition (1961) says that the phrase "look nine ways for Sunday" is nautical slang from circa 1850 for "to squint." That definition might be the one intended in the Godey's Magazine extract (above) describing Miss Bessy's "extraordinary physiognomical phenomenon."