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.
- <?php
- if(isset($_POST['submit'])){
- $datetime1=newDateTime($_POST['start_date']);
- $datetime2=newDateTime($_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>
<?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