We're only a few months into 2024, but the S&P 500 (^GSPC 1.02%) has started off the year with a bang. The index is currently up by more than 8% this year alone and it's soared by a whopping 44% from its lowest point in October 2022.

Now that the S&P 500 has reached a new all-time high and is well into bull market territory, some investors may be concerned that the best time to buy has already come and gone. Stock prices are surging, and it's becoming more expensive by the day to invest.

At the same time, though, if the market continues to climb, you may miss a valuable wealth-building opportunity by not investing right now. So does that mean now is a smart time to buy? Or have you already missed your best chance to invest? Here's what you need to know.

Dollar bills flying off a stack of cash.

Image source: Getty Images.

Is it too late to invest in the stock market?

While stock prices are up significantly compared to a year or two ago, the good news is that with the right strategy, there's never necessarily a bad time to invest.

Building wealth in the stock market is a long-term strategy. Rather than getting caught up in the market's short-term movements and trying to invest at just the right time, you can often earn more by investing consistently and staying in the market for the long haul.

Time in the market is far more important than timing the market, and the more years you can give your investments to grow, the more you can potentially earn. Even if you invest at a seemingly terrible moment, you could still earn more than if you wait for a "safer" time to buy.

For example, say you had invested in an S&P 500 index fund in January 2009, amid the Great Recession. That may have seemed like a bad time to buy at the time, as almost immediately afterward, the market experienced a fairly significant drop before bottoming out in March 2009. But by today, you'd still have earned total returns of more than 471%.

^SPX Chart

^SPX data by YCharts

But let's say that you were feeling rattled by the market's volatility, and instead of investing in 2009, you decided to wait a couple of years and start buying in January 2011. The market was well into a new bull market at that point, and despite some short-term hiccups, stock prices were steadily rising. However, by today, you'd have only earned returns of just under 311%.

^SPX Chart

^SPX data by YCharts

In another scenario, say you were worried you'd already missed out on the best time to buy and that by investing after stock prices had surged, you'd be limiting your earnings. So instead, you waited another couple of years, beginning to invest in January 2013. By today, you'd have only earned total returns of around 262%.

^SPX Chart

^SPX data by YCharts

Of course, to truly maximize your earnings, you'd need to invest when the market is at its lowest. If you'd invested back in October 2022 when the S&P 500 bottomed out, you'd have earned substantial returns by today. But hindsight is 20/20, and since you can't go back in time, your only options are to invest now or wait. Between those two options, investing now is almost always more lucrative.

Nobody knows where the market is headed in the short term. Stock prices could continue to surge for many more years, or there could be a slump on the horizon. But the market's long-term potential is far more important than its short-term performance, and the more time you have to let your money grow, the more you can earn.

The key to maximizing your earnings

As long as you're keeping a long-term outlook, it doesn't necessarily matter when you invest. However, to keep your money as safe as possible, you'll need to be careful about where you invest.

Even shaky stocks can thrive when the market is booming, but they'll have a much tougher time recovering from downturns. If you're investing in the wrong places, you could easily lose more than you gain in the stock market.

There's no single correct way to invest, but the strongest stocks are from companies with solid fundamentals. This can include everything from a competitive advantage in the industry to strong financials to a knowledgeable and capable leadership team. The healthier a company is, the more likely it is to pull through tough economic times and experience long-term growth.

The market has had an incredible run over the past year and a half, but that doesn't mean it's too late to buy. By getting started investing now, keeping a long-term outlook, and investing in the right stocks, you can maximize your earnings in the stock market.