Only anonymous ("everyone") sharing links can be configured to expire, and by default they are valid indefinitely. The maximum value is 2 years (730 days), and yes, they apply retroactively.
Details are here: https://learn.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off?WT.mc_id=365AdminCSH_spo#advanced-settings-for-anyone-links