Jump to content

Differnce in days


DeanWhitehouse

Recommended Posts

I have this code for the difference in days , but i think i am doing something wrong as it is not returning the correct result.

 

<?php 
$today1 = $rows['started_on']; 
$today1 = date("d.m.Y",strtotime($today1)); 
$f_date1 = $rows['completed_on'];
$f_date1 = date("d.m.Y",strtotime($f_date1 )); 
$difference = intval(($f_date1 - $today1)/86400+1);  
echo $difference;
?>

 

The $rows are stored in this format (2008-08-07 21:43:10), any ideas. Note: i will need it to work out the amount of days from when i started to when i finished, that may go into another month.

Link to comment
https://forums.phpfreaks.com/topic/125126-differnce-in-days/
Share on other sites

bit of a prob

this is my code

$sql = "SELECT *, (TO_DAYS(".$rows['started_on'].") - TO_DAYS(`".$rows['completed_on']."`)) as `difference`  FROM sites WHERE id = '$site_id' AND member_id = '$id'";// this is my problem, the vars need to be retireved from the db , do i need to reset the pointer if so how?
$query = mysql_query($sql);
$number = mysql_num_rows($query);
?>
<p align="center" style="text-align:left; margin-left:5px;">	
<?php
if($number == 0)
{
	echo "Either the site is not registered , or the site is not registered to this username. Please check and try again.";
}
else
{
	while($rows = mysql_fetch_assoc($query))
	{
	echo $rows['difference'];
                }
?>

Link to comment
https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646733
Share on other sites

I dont think any one actually saw the comment so here it is

this is my problem, the vars need to be retireved from the db , do i need to reset the pointer if so how?

 

corresponds to this line

$sql = "SELECT *, (TO_DAYS(".$rows['started_on'].") - TO_DAYS(`".$rows['completed_on']."`)) as `difference`  FROM sites WHERE id = '$site_id' AND member_id = '$id'";

Link to comment
https://forums.phpfreaks.com/topic/125126-differnce-in-days/#findComment-646751
Share on other sites

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.