latest Post

How to calculate age using html with php program

Program :

<html>
<body>
<form action="welcome.php" method="post">
DOB: <input type="text" name="dob"><br>
<input type="submit">
</form>
</body>
</html>

File name : welcome.php

<?php
$birthDate=$_POST["dob"];
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
    ? ((date("Y") - $birthDate[2]) - 1)
    : (date("Y") - $birthDate[2]));
  echo "Age is:" . $age;
//$date1=getAge($birthday);
?>

Output :



About Open Learning Creative

Open Learning Creative
Recommended Posts × +

0 comments:

Post a Comment

PHP Registration form using GET, POST Methods with example

Program : HTML Code <html> <head> <title>Student Info</title> </head> <body><center> ...