
Restar 2 fechas y obtener edad en años.
Publicado por Bladimir (5 intervenciones) el 16/03/2015 02:01:29
Hola a todos. Tengo un archivo html donde hay 3 inpu. En uno de ellos se carga la fecha actual cuando se carga la pagina en formato dd/mm/yyyy, en otro el usuario debe ingresar su fecha de nacimiento en formato dd/mm/yyyy. En el tercer input debe aparecer, al hacer click en el button, la edad en años. ¿Como se haria con javascript? El codigo es el siguiente:
Gracias por la ayuda.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>RHM</title>
</head>
<script type="text/javascript">
window.onload = function(){
fecha = new Date();
texto = document.getElementById("fechaing");
texto.value = fecha.getDate() + "/" + (fecha.getMonth() + 1) + "/" + fecha.getFullYear();
}
</script>
<script type="text/javascript">
function startTime(){
today = new Date;
h=today.getHours();
}
</script>
<body>
<form name="elegir" method="post" action"<?=$_SERVER['PHP_SELF']?>>
<fieldset>
<legend>
<b> Prueba: </b>
</legend>
<p> <b>Fecha de nacimiento:</b> <input type="text" name="fechanac"/>
<b>Edad:</b> <input type="text" name="edad"/>
<p> <b>Fecha de Ingreso: </b><input type="date" id="fechaing"> </p>
</fieldset>
<p>
</p>
<p align="center" ><input type="button" value="Restar" name="restar"/></p>
</form>
</body>
</html>
Gracias por la ayuda.
Valora esta pregunta


0