🎓 Free Capstone Projects with Full Documentation, ER Diagrams & Source Code — Updated Weekly for 2026
👨‍💻 Free Source Code & Capstone Projects for Developers

How to Add Date and Time in PHP

Hello Guys this tutorial is all about How to Add Simply Seconds, Minutes, Hours, Days, Months and Years to a Date and Time in PHP. 

In this tutorial I will give you an idea on How to Add Simply Seconds, Minutes, Hours, Days, Months and Years to a Date and Time in PHP

Let’s Get Started:

1.Create a form name it index.php and add this code:

<!DOCTYPE html>
<html>
<head>
<title>How to Add Simply Seconds, Minutes, Hours, Days, Months and Years to a Date and Time in PHP</title>
<body>
	<h2>Our Date and Time: 2017-08-28 13:05:05</h2>
	<?php
		$olddate="2017-08-28 13:05:05";
		$newdate="";
	?>
	<form method="POST">
		<input type="text" name="number">
		<select name="what">
			<option value="seconds">Seconds</option>
			<option value="minutes">Minutes</option>
			<option value="hours">Hours</option>
			<option value="days">Days</option>
			<option value="months">Months</option>
			<option value="years">Years</option>
		</select>
		<input type="submit" name="add" value="Add">
	</form>
	<?php
		if (isset($_POST['add'])){
			
			$number=$_POST['number'];
			$what=$_POST['what'];
			
			echo "<br> You have added ".$number." ".$what.".";
			$newdate=date('Y-m-d H:i:s', strtotime("+$number $what", strtotime($olddate)));
			
		}
	
	?>
	<h2>New Date and Time: <?php echo $newdate; ?> </h2>
</body>
</head>
</html>

Done! Go and Test the program afterwards!

If you have any comments or suggestions about the How to Add Simply Seconds, Minutes, Hours, Days, Months and Years to a Date and Time in PHP Just message us directly:

Download Source Code here:

Related PHP Projects

Leave a Comment