The past several months have been confusing for many investors. While the stock market has been on its way up, many experts are still calling for a recession later this year.

The S&P 500 has surged by around 22% from its lowest point in October, while the Nasdaq is up by 32% since it bottomed out in December. This has led many to claim that we're in the early stages of a bull market, with prices only going up from here.

Meanwhile, recession concerns aren't going away. Analysts at JPMorgan Chase believe there's a greater than 50% chance we'll see a recession in 2023. And researchers at Deutsche Bank are feeling even more pessimistic, giving it a "near 100%" probability that a recession will hit in the next 12 months.

So is it really safe to invest right now? Or should you wait until the market and economy stabilize a bit more? Here's legendary investor Warren Buffett's best advice.

Closeup profile of Warren Buffett.

Image source: The Motley Fool.

Should you invest now or wait?

During periods of economic volatility, it can be tempting to hold off on investing. But according to Warren Buffett, that's one of the worst moves you could make right now.

Back in 2008, at the height of the Great Recession, Buffett wrote an opinion piece for The New York Times to help reassure panicked investors. In it, he explains that while recessions are daunting, the tough times are some of the best opportunities to invest.

"A simple rule dictates my buying," he writes. "Be fearful when others are greedy, and be greedy when others are fearful."

If a recession is on the horizon, the stock market may sink once again. While that's not exactly encouraging, investing during a slump means you can load up on high-quality stocks for a fraction of the price. Even right now, many stocks are still priced well below their peaks -- making it a smart buying opportunity.

"In short, bad news is an investor's best friend," Buffett goes on to write. "It lets you buy a slice of America's future at a marked-down price."

The key to surviving a recession

It's easy to get caught up in the market's short-term fluctuations or worry about what may happen over the next few months. But what really matters in investing is the market's long-term potential.

Historically, the market has a flawless record of recovering from downturns. Not only that, but it's managed to earn positive total returns despite experiencing extreme short-term volatility.

In the past two decades alone, the market has faced some of the worst crashes and recessions in history -- from the dot-com meltdown to the Great Recession to the COVID-19 crash, as well as the current slump. Despite everything, though, the S&P 500 is still up by nearly 200% since 2000.

^SPX Chart

^SPX data by YCharts

The key to surviving a recession, then, is to keep a long-term outlook. It's possible that things will get worse before they get better. But by continuing to invest during downturns, you could see substantial earnings during the inevitable recovery period.

Warren Buffett via The New York Times said:

I can't predict the short-term movements of the stock market. I haven't the faintest idea as to whether stocks will be higher or lower a month or a year from now. What is likely, however, is that the market will move higher, perhaps substantially so, well before either sentiment or the economy turns up. So if you wait for the robins, spring will be over.

It's not easy to invest in times like these, but doing so could help you make a lot of money over time. Regardless of what the future holds for the market, investing is safer than it may seem right now.