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.
- <?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.