LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 July 21 2014

Ramii
Member

PHP date calculation and addition

using Html / PHP :
i have two textbox i want to insert date in the first textbox and when inserting the date the second textbox will be filled automatically with the date of the first textbox + 10 years.

Example :

Start Date: 01/01/2014 (When filling here)

automatically ---->End Date: 01/01/2024

Sorry guys but im new to php and html... i work in a small company and im trying to create a small application but i have this small problem. thanks in advance.

Offline

#2 July 21 2014

rtp
Member

Re: PHP date calculation and addition

check this and see if it helps.
http://stackoverflow.com/questions/5172 … -timestamp

as mentioned from the guys, you should do it in Javascript

Last edited by rtp (July 22 2014)

Offline

#3 July 21 2014

AliMJD
Member

Re: PHP date calculation and addition

See if this peace of Code Helps You and Good Luck With your Application

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
var x=document.getElementById("fname");
var y=document.getElementById("fname2");


var d = new Date(x.value);

y.value=((d.getMonth()+1)+"-"+d.getDate()  + "-" +(d.getFullYear()+10));

}
</script>
</head>
<body>

<input type="date" id="fname" onchange="myFunction()">
<input type="text" id="fname2" disabled>


</body>
</html>

Last edited by AliMJD (July 21 2014)

Offline

#4 July 21 2014

Ra8
Member

Re: PHP date calculation and addition

You don't need PHP to do that, you can use JavaScript. This is a nice JS library that handles dates and times: momentjs.com

Offline

#5 July 22 2014

Ramii
Member

Re: PHP date calculation and addition

Thanks Guys! I Really appreciate it !

Offline

Board footer