Jump to content

calculate between 2 dates


haruya

Recommended Posts

i want to ask about how to calculate the dates between 2 dates and it automatically show the difference between 2 dates.

 

i already have the code to calculate between those dates, but i cant show it directly, for example

 

if you choose 3 Jan 2012 for the start date and 6 Jan 2012 for end date,

 

and it will automatically show the difference between 2 dates on the side.

 

how do i do that?

 

please help

Link to comment
Share on other sites

This is my php code, i actually want to save the gap between 2 dates into database, but still it wont go through.

 

this date picker is i created myself using dropdown list, i dont know how to use datetime picker..

 

 

$con = mysql_connect("localhost","root","abc123");

$db = mysql_select_db("lms",$con);

$id = $_REQUEST["emp_id"];
$dateapp = $_REQUEST["dateapp"];
$period = $_REQUEST["period"];
$types = $_REQUEST["types"];
$date1 = $_REQUEST["date"];
$month1 = $_REQUEST["month"];
$year1 = $_REQUEST["year"];
$date2 = $_REQUEST["date2"];
$month2 = $_REQUEST["month2"];
$year2 = $_REQUEST["year2"];

//$totime3 = strtotime("$date1 $month1 $year1");
//$date3 = date ("Y-m-d",$totime3);

//$totime4 = strtotime("$date2 $month2 $year2");
//$date4 = date ("Y-m-d",$totime4);

$diff = (strtotime("$date2 $month2 $year2") - strtotime ("$date1 $month1 $year1")) / (60*60*24);

$diff1 = $diff;


$query = "INSERT INTO leave_request(leave_request_id,date_applied,emp_id,leave_type_id,leave_period_id,leave_status,leave_length_day) VALUES('',NOW(),'$id','$types','$period','PENDING','$diff1')";

$query2 = "insert into employee_leave_quota(leave_period_id,emp_id) values ('$period','$id')";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.