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 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 = new DateTime($_POST['start_date']);
  4.     $datetime2 = new DateTime($_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>

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

Phone: (+91) 8800417876
Noida, 201301
Attention Required! | Cloudflare

Sorry, you have been blocked

You are unable to access ressim.net

Why have I been blocked?

This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.

What can I do to resolve this?

You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.