The Great Krabby Patty Famine was an era of Bikini Bottom history that lasted 6 days, featured in The SpongeBob Movie: Sponge Out of Water and the book The SpongeBob Movie: Sponge Out of Water: The Junior Novelization.
The famine started when Burger Beard the Pirate discovered the Magic Book and used it to make the Krabby Patty secret formula disappear and created a rupture in the social order of Bikini Bottom, turning it into an apocalyptic civilization.
Mr. Krabs blamed Plankton for the disappearance of the formula and tried to force him to say where it was, but because Plankton didn't know he got nowhere. Fortunately, SpongeBob's sympathy came through and he escaped with Plankton, causing Bikini Bottom to become savage just to find the pair.
Very soon, the two build a time machine and traveled four days to the future where they found Patrick heavily aged and the town a barren wasteland. They soon went back to the moment the formula disappeared but accidentally grabbed the wrong bottle.
This caused SpongeBob to volunteer as a sacrifice and this was immediately accepted by the people who captured him quickly.
Eventually, when SpongeBob smelt the Krabby Patty, Bikini Bottom snapped back into its senses and tore off their clothes to go find the formula. When SpongeBob and the gang defeated Burger Beard and retrieved the formula, Bikini Bottom returned to its patty-loving self.