PHP – Calculate experience in months, years and days from two given dates

PHP – Calculate experience in months, years and days from two given dates

In this post we will give you information about PHP – Calculate experience in months, years and days from two given dates. Hear we will give you detail about PHP – Calculate experience in months, years and days from two given datesAnd how to use it also give you demo for it if it is necessary.

In this tutorial, I will tell you how to calculate total experience of your job in months, years and days from two given dates using PHP script.

Using this script, you can calculate your age from birth date to present day.

  1. <?php
  2. if(isset($_POST['submit'])){
  3.     $datetime1=newDateTime($_POST['start_date']);
  4.     $datetime2=newDateTime($_POST['end_date']);
  5.     $interval=$datetime1->diff($datetime2);
  6.     echo$interval->format('%y years %m months and %d days');
  7. }
  8. ?>
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12.     <title>Online Experience Calculator</title>
  13. </head>
  14. <body>
  15. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  16. Start Date :<input type="date" name="start_date" required="required"><br>
  17. End Date :<input type="date" name="end_date" required="required"><br>
  18. <input type="submit" name="submit" value="Calculate">
  19. </form>
  20. </body>
  21. </html>
<?php
if(isset($_POST['submit'])){
	$datetime1 = new DateTime($_POST['start_date']);
	$datetime2 = new DateTime($_POST['end_date']);
	$interval = $datetime1->diff($datetime2);
	echo $interval->format('%y years %m months and %d days');
}
?>

<!DOCTYPE html>
<html>
<head>
	<title>Online Experience Calculator</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Start Date : <input type="date" name="start_date" required="required"><br>
End Date : <input type="date" name="end_date" required="required"><br>
<input type="submit" name="submit" value="Calculate">

	
</form>
</body>
</html>

The $_SERVER["PHP_SELF"] is a super global variable that returns the name and path of the current file.

It’s very easy with PHP to manipulates dates.

Show Demo

Hope this code and post will helped you for implement PHP – Calculate experience in months, years and days from two given dates. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  68  =  71

We accept paid advance and paid guest Posting on our Site : Contact US