Rohit265 Posted September 12, 2022 Share Posted September 12, 2022 Hello, How can I get number of days remaining to a date, which does not add year, For ex, In this code, I will have to change the year (2022) once Christmas date passes, but I do not want to change the year every time. $futureDate = '2022-12-25'; $d = new DateTime($futureDate); echo $d->diff(new DateTime())->format('%a'); //--> 321 printf("\n"); Quote Link to comment https://forums.phpfreaks.com/topic/315315-days-until-a-date/ Share on other sites More sharing options...
Solution Barand Posted September 12, 2022 Solution Share Posted September 12, 2022 Try $futureDate = new DateTime('dec 25'); $now = new DateTime('today'); if ($now > $futureDate) { $futureDate->modify('+1 year'); } echo $now->diff($futureDate)->days; Quote Link to comment https://forums.phpfreaks.com/topic/315315-days-until-a-date/#findComment-1600449 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.