Title: Records of prime ministers of the United Kingdom
Content:  A prime minister's "term" is traditionally regarded as the period between their appointment and resignation, dismissal (or death, in the case of those who die in office), with the number of general elections taking place in the intervening period making no difference. The only prime minister to serve four terms under that definition was William Ewart Gladstone (3 December 1868 – 20 February 1874, 23 April 1880 – 23 June 1885, 1 February 1886 – 25 July 1886 and 15 August 1892 – 5 March 1894).
Title: List of prime ministers of the United Kingdom by length of tenure
Content:  This article lists each prime minister of the United Kingdom in order of term length. This is based on the difference between dates; if counted by number of calendar days all the figures would be one greater. Of the 55 prime ministers, nine served more than 10 years while seven have served less than a year. Robert Walpole is the only person to have served as Prime Minister for more than two decades. George Canning served for less than four months before his death.
Title: List of prime ministers of the United Kingdom by length of tenure
Content:  In this table, "Terms in office" is the number of separate, discontiguous periods served as Prime Minister.
Title: Records of prime ministers of the United Kingdom
Content:  The prime minister with the longest single term was Sir Robert Walpole, lasting 20 years and 315 days from 3 April 1721 until 11 February 1742. This is also longer than the accumulated terms of any other prime minister. The shortest period in office is more confused, depending on the criteria. The shortest ever period was only two days, a record held by Lord Bath, from 10 to 12 February 1746, who was asked to form a government but was unable to find more than one person who would agree to serve in his cabinet. A satirist of the time wrote: "the minister to the astonishment of all wise men never transacted one rash thing; and, what is more marvellous, left as much money in the Treasury as he found in it." 
Title: Records of prime ministers of the United Kingdom
Content:  until his death on 1 July 1782. However, combined with his first term (13 July 1765 – 30 July 1766) his total time in office was 1 year and 113 days, which exceeds the total periods of several other prime ministers. (The Duke of Wellington had also served as Prime Minister between 1828 and 1830.) Consequently, the prime minister with the total shortest period in office was George Canning, whose sole term lasted 119 days from 12 April 1827 until his death on 8 August 1827. The prime minister with the longest period between the start of their first appointment and the end of their final term was the Duke of Portland, whose first term began on 2 April 1783 and whose second and final term ended on 4 October 1809.
Title: United Kingdom
Content:  (MP). MPs hold office for up to five years and are always up for relection in general elections. The Conservative Party, Labour Party and Scottish National Party are, respectively, the current first, second and third largest parties (by number of MPs) in the House of Commons. The prime minister is the head of government in the United Kingdom. Nearly all prime ministers have served as First Lord of the Treasury and all prime ministers have continuously served as First Lord of the Treasury since 1905, Minister for the Civil Service since 1968 and Minister for the Union since 2019. In modern times, the prime minister is, by 
Title: List of prime ministers of the United Kingdom by age
Content:  This is a list of prime ministers of the United Kingdom by age. This table can be sorted to display prime ministers of the United Kingdom by name, order of office, date of birth, age at appointment, length of retirement, or lifespan. Age at appointment is determined by the day a prime minister assumed office for the first time. Length of retirement is determined from the day a prime minister leaves office for the final time until their death. Two measures of longevity are given; this is to allow for the differing number of leap days occurring within the life of each prime minister. The first figure is the number of days between date of birth and date of death, allowing for leap days; in parentheses the same period given in years and days, with the number of whole years that the prime minister had lived, and the days being the remaining number of days from their last birthday. Where the prime minister in question is still living, their longevity is measured up to.
Title: Records of prime ministers of the United Kingdom
Content:  10 December 1756 aged 21 years and 73 days. He also had the shortest period as an MP enjoyed by a prime minister, nearly five months, representing two successive seats (the first of which he only held for 11 days before being elected for his second) until going to the House of Lords when he succeeded his father as the 3rd Duke of Grafton on 6 May 1757, eleven years before his term of office began. The longest service as MP was enjoyed by Sir Winston Churchill, who sat for a total of 63 years and 360 days, for five successive seats, between 1 October 1900 and retiring on 25 September 1964, 
Title: Prime Minister of the United Kingdom
Content:  The prime minister of the United Kingdom is the head of government in the United Kingdom. The prime minister advises the sovereign on the exercise of much of the royal prerogative, chairs the Cabinet and selects its ministers. As modern prime ministers hold office by virtue of their ability to command the confidence of the House of Commons, they sit as a member of Parliament. The office of prime minister is not established by any statute or constitutional document, but exists only by long-established convention, whereby the reigning monarch appoints as prime minister the person most likely to command the confidence 
Title: Records of prime ministers of the United Kingdom
Content:  The prime minister who lived the longest after leaving office for the final time was the Duke of Grafton, who left office on 28 January 1770 and died on 14 March 1811, a total of 41 years and 45 days. The oldest living former prime minister, John Major, left office on 2 May 1997. If he lives until 17 June 2038, he will surpass FitzRoy's record, by which point he will be 95 years and 80 days old. In recent years, the prime minister who lived the longest after leaving office was Edward Heath, whose term ended on 4 March 1974; he died on 17 July 2005, 31 years and 135 days later.

Question: how long is a prime minister term in uk?
Answer: At Her Majesty's pleasure.