I'm sure you searched for this solution before posting. But we have already solved this in the Watchlist topic. I believe the Watchlist solution is far more useful than having this displayed on a chart. But if you really think a chart label is more useful then reply back in the comments section below and I'll provide the solution here.
Edit: The solution for the watchlist column does not work for a chart study label.
I tested this on a chart and it requires the right-side "Expansion Area" is set to include the date in which the next earnings event is scheduled to occur. (I know, sort of defeats the purpose). The example I used was AAPL. On the watchlist version this shows a value of -9. Which indicates the next earnings is 9 trading sessions in the future. When we apply this to a chart with Expansion Area set to zero the label displays a value of zero. When you set the Expansion Area to 10 the labels displays a value of -9.
Just in case anyone can still use it under these conditions I will provide the code to add that label to your chart.
AddLabel(yes, Concat("Days Till Earnings: ", GetEventOffset(Events.EARNINGS, 0)), Color.WHITE);
For reference, here is a link to the post to do this in a watchlist column:
https://www.hahn-tech.com/ans/watch-list-column/