All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Add 30 Minutes To Time In PHP

Last Updated : Jul 1, 2023

Add 30 Minutes To Time In PHP

In this tutorial we will show you the solution of add 30 minutes to time in PHP, first there are many ways to help of which we can add time to time in PHP.

Here, adding time to time means adding minutes to time. So, let us see how to do this with the help of the example given below.

Step By Step Guide On Add 30 Minutes To Time In PHP :-

Now, below is an example provided with help of which we can see how to add minutes to time. In this example, we are going to use the strtotime() function.

<!DOCTYPE html>
<html>
<head>
   <title> Add 30 minutes to time in PHP </title>
</head>
<body>
<h1>
 TalkersCode
</h1>
<h2>
 Add 30 minutes to time in PHP
</h2>
<?php
// use strtotime() function
$add_time= strtotime('2022-11-07 09:18:00 + 30 minute');
// prints or display date to screen
echo date('Y-m-d H:i:s', $add_time);
?>
</body>
</html>
  1. As, here we see that we that in above example we show you an example in which HTML and PHP codes are used.
  2. Let us understand the above codes step by step.
  3. Here, first of all, we create a basic structure of HTML, in which we use <!DOCTYPE html> which defines the type of document. And next one is our HTML tags. These tags are paired tags and all the data regarding HTML is written inside these tags.
  4. After we use our head tag which is again paired tag and contains the title and meta information of the webpage. The data written inside the head is not shown on the webpage.
  5. Now, next is our title tag which defines the title of the webpage. The tag which has its closing tag is known as a paired tag. So, this is again a paired tag.
  6. Now, next is the body which is the main tag of HTML. The data which we have written inside the body is shown on the webpage. Mostly all tags which are helpful to show data or information on the screen are written under the body tag.
  7. Here, as above we see inside our PHP codes, we first store the date inside a variable in which we want to add 7 days using PHP.
  8. Here, as we see that we create a variable having the name add_time in which we store a date with time (you can also get the current date and time to add custom time and display). After that we simply add minutes to this, here we use 30 minutes because we want to add 30 minutes. This whole process occurs under the strtotime() function as you see above in the code.
  9. After that we just display the date with time in the required format to show you that 30 minutes have been added to our custom date.

Conclusion :-

At last, in conclusion, here we can say that with the help of this article we can understand how to add 30 minutes to time using PHP.

I hope this tutorial on add 30 minutes to time in PHP helps you and the steps and method mentioned above are easy to follow and implement.