QuizCure
Find Available Solution Here!

How to Get PHP Date + 1 Day

Deepak Sep 10, 2023

During programming, we might be required to get tomorrow's date or the next date for any given date. We will go through several methods to cover the current topic of how to get the next date in PHP. Stay tuned!

But before going to determine tomorrow or next Nth date it is recommended to check PHP date/time functions and their usage.

We have explained some DateTime functions definitions and examples which we will use here.

Let's dive into the following step by step approach to learn How to Get PHP Date + 1 Day with examples:

PHP add 1 day to current date

echo date('j F, Y',strtotime("+1 days"));
 

Result: 31 January, 2022

Note: Current Server Date was: 30 January 2022 when calculating tomorrow using above code

Code Explanation:

  • strtotime converts English text "+1 days" into a corresponding Unix timestamp.
  • Timestamp received from strtotime function further passed to date function to get next date in given format j F, Y

Find Next Date for any Given date using strtotime function

$givenDate = "2022-01-31";
$timestampForGivenDate = strtotime ( $givenDate );
$englishText = '+1 day';
$requireDateFormat = "Y-m-d";
echo date($requireDateFormat,strtotime ( $englishText , $timestampForGivenDate )) ;

Result: 2022-02-01

Code Explanation:

  • Let's say the We have given 2022-01-31
  • First converted given date into a timestamp and stored in $timestampForGivenDate
  • English text +1 day is applied here to find the next day.
  • Described here to get a date in Y-m-d format. You may change the date format as per your programming needs.
  • Now we have a timestamp for a given date stored in $timestampForGivenDate. Next, we need a timestamp for the next day. Therefore strtotime ( $englishText , $timestampForGivenDate ) used to get a timestamp for the next date.
  • Further passed next date timestamp to date function with expected date format Y-m-d. That's it.

Get next 7 day date

We can follow the same way as per the previous example to find the next 7th day's date or the Next Nth day's date.

To find Next 7th Date from today:

echo date('j F, Y',strtotime("+7 days"));
    

Just use English text "+7 days" to get the timestamp and pass to date function as demonstrated above

Find below code in php add days to date to find Next 7th date

$givenDate = "2022-01-31";
$timestampForGivenDate = strtotime ( $givenDate );
$englishText7 = '+7 day';
$requireDateFormat = "j F, Y";
echo date($requireDateFormat,strtotime ( $englishText7 , $timestampForGivenDate )) ;

Result: 7 February, 2022

Get the previous date in PHP

We have already covered calculating the date minus 1 day from today or for any given date. Please visit here to learn more.

How to Get PHP Date + 1 Day

During programming, we might be required to get tomorrow's date or the next date for any given date. We will go through several methods to cover the current topic of how to get the next date in PHP. Stay tuned!

But before going to determine tomorrow or next Nth date it is recommended to check PHP date/time functions and their usage.

We have explained some DateTime functions definitions and examples which we will use here.

Let's dive into the following step by step approach to learn How to Get Next Date in PHP with examples:

Brain Exercise

How many times clock hands are in a straight line but in the opposite direction?

The hands of a clock make a straight line multiple times in a day. Find how many times clock hands are in a straight line but in the opposite direction.

Was this post helpful?

Send Feedback

Connect With QuizCure


Follow Us and Stay tuned with upcoming blog posts and updates.

Contributed By

Deepak

Deepak

QC STAFF
51 Posts
  • PHP
  • JAVA
  • PYTHON
  • MYSQL
  • SEO

You May Like to Read

Other PHP Articles