The phrase fair-weather friend designates a person who is friendly only when it is easy or convenient to be so, whose friendship cannot be relied on in times of difficulty.
These are the earliest occurrences of the phrase that I have found, in chronological order:
1-: From The grand Tryal: Or, Poetical Exercitations upon the Book of Job. Wherein, Suitable to each Text of that sacred Book, a modest Explanation, and Continuation of the several Discourses contained in it, is attempted (Edinburgh: Printed by the Heir of Andrew Anderson […], 1685), by William Clark:
Friends did I call them,—no I do mistake,
Such are not friends, who do their friend forsake
In Misery, for at such time alone,
As by a Test, true friendship should be known.
But such have Hearts as hard, and black, as Ice,
They’r of no value, no esteem, no price.
Rugged, unpolish’d, cold, as is the snow,
Instinct of Nature sure they do not know.
Friends for a Sun-shine of Prosperity,
O worthy friends! but when the troubled Skye,
Portends a Storm, and Clouds begin to reel,
Then those Fair-weather-friends bid us farewel.
2-: As the translation of the Spanish phrase “Amígo del buén tiémpo”—from A New Spanish Grammar, More perfect than any hitherto publish’d. All the Errors of the former being Corrected, and the Rules for Learning that Language much improv’d. To which is added, A Vocabulary of the most necessary Words: Also a Collection of Phrases and Dialogues Adapted to Familiar Discourse (London: Printed for T. Meighan […]. J. Batley […], and T. Cox […], 1725), by John Stevens (c.1662-1726):
Amígo del buén tiémpo, múdase con el viénto. A fair weather friend, turns with the wind.
3-: From a letter that the English poet Alexander Pope (1688-1744) wrote to the English poet and playwright John Gay (1685-1732) on 1st October 1730—as published in Mr. Pope’s Literary Correspondence For Thirty Years, from 1704 to 1734. Being a Collection of Letters, Which passed between him and Several Eminent Persons (London: Printed for E. Curll […], 1735):
I shall certainly make as little court to others, as they do to me; and that will be none at all. My Fair-Weather-Friends of the Summer are going away for London, and I shall see them and the Butterflies together, if I live till next Year; which I would not desire to do, if it were only for their sakes.
4-: From the last chapter of The Adventures of Peregrine Pickle. In which are included, Memoirs of a Lady of Quality (London: Printed for R. Baldwin, and J. Richardson, […] and D. Wilson and T. Durham […], 1758), by the Scottish novelist Tobias Smollett (1721-1771):
A town-house was hired, and an handsome equipage set up, in which the new-married pair appeared at all public places, to the astonishment of our adventurer’s fair-weather friends, and the admiration of all the world.
5-: From Familiar Essays, on Interesting Subjects (London: Printed for Leigh and Sotheby […], 1787):
Ethelinda was obliged to retire, with her mother, to a small and obscure village, on a scanty pittance, which however they husbanded so as to be ever above want, and above obligation. […] Ethelinda still lives admired and respected by the few who have the pleasure of her acquaintance; though neglected and forgotten by the fair-weather friends who once flattered her in her life of grandeur.
6-: From Fleetwood; Or, The New Man of Feeling (New York: Printed for I. Riley & Co. […], 1805), by the English social philosopher and novelist William Godwin (1756-1836):
Miss Matilda Rancliffe was what is well expressed by the phrase, a fair-weather friend; she loved no dismals; her step was airy; the tone of her voice was frolic and cheerful; and she owned that her sensibilities were so overpowering, as to make the impulse in her to fly from the presence of distress, irresistible.
7-: From Obsolete Ideas. In Six Letters, addressed to Maria, by a Friend (Sherborne: Printed for the author, by James Langdon […], 1806):
What a despicable mind must that person have who can forsake a friend in a time of trouble; one with whom they have gladly spent their joyous hours? A fair-weather-friend is a contradiction in terms; but we sometimes hear of such beings. It would be a good rule to lay down to yourself never to cultivate any degree of intimacy with persons who neglect their afflicted connections, and appear to fix all their happiness in a succession of amusements. While you are in health and prosperity they will be very attentive, and, perhaps, very pleasing; but the moment you are the subject of affliction, you will be deserted.