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
https://forums.phpfreaks.com/topic/266799-calculate-between-2-dates/
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')";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.