To calculate date by adding number of days, months or even years, such as how do we know 15 days after today what date is it? there are different way to find datetime after adding or subtract month and return result as new datetime calculated. In this tutorial I will show how to adding number years, days on any specific datetime in PHP with examples.
Also read
Example #1 - Using date_add()
Output
2022-06-22 05:52:44 AM
date_interval_create_from_date_string()
will return an DateInterval object by following relative parts of the string.
Example #2 - Using date_add()
Output
Date => 2022-05-31 05:52:44 AM
Date added => 2022-06-15 02:03:44 PM
Example #3 - Using strtotime()
Output
Date => 2022-05-31 5:52:44 AM
Date added => 2022-06-01 07:55:46 AM
Example #4 - Using modify()
Output
2022-06-04 10:53:44 AM
Example #1 - Using date_sub()
Output
Date => 2022-05-31 05:52:44 AM
Date subtract => 2022-05-15 09:41:44 PM
--adres-
Example #2 - Using strtotime()
Output
Date => 2022-05-31 5:52:44 AM
Date subtract => 2022-05-30 07:55:46 AM
Example #3 - Using modify()
Output
Date subtract => 2022-05-27 10:53:44 AM
Hope your will learn how to add days to datetime in PHP with these simple examples. Thank you
PHPAs the founder and passionate educator behind this platform, I’m dedicated to sharing practical knowledge in programming to help you grow. Whether you’re a beginner exploring Machine Learning, PHP, Laravel, Python, Java, or Android Development, you’ll find tutorials here that are simple, accessible, and easy to understand. My mission is to make learning enjoyable and effective for everyone. Dive in, start learning, and don’t forget to follow along for more tips and insights!. Follow him