Time diff between filetime in mysql with current time
Posted: Tue Oct 13, 2009 7:30 am
Hi All,
I am new to this Forum, and i really need help..because i stuck with a problem in php.
I am trying to learn php myself..now i am working with finding the difference of two time.
what am doing is that: I am uploading a file..when the submit button pressed..the current date and time of that will upload to my database automatically..Am using the Now() function to do so.
And when i am trying to find the difference between the file uploaded time and the current time the answer that am getting is 0.
but i want the answer like: If file uploaded time:2009-10-11 23:46:37
current time:2009-10-12 33:50:45
difference time: 1 day 10:04:08
Is that possible:
this is my code:
<?php
$db = mysql_connect("localhost","ttt","");
mysql_select_db("date");
$pname = $_REQUEST['pname'];
$time_now = date('Y-m-d H:i:s');
$pdesc = $_REQUEST['pdesc'];
$ftype = $_FILES['pfile']['type'];
$result = date("H:i:s",mktime(0,0,($currDate - $oldDate),0,0,0));
$fname = $_FILES['pfile']['name'];
if ($_FILES['pfile']['size'] <= $_REQUEST['MAX_FILE_SIZE'])
{
$fdata = fread(fopen($_FILES['pfile']['tmp_name'], "rb"),
$_FILES['pfile']['size']);
$fdata = base64_encode($fdata);
$sql = "INSERT INTO pictures (poster_name,pdesc,ftype,fname,fdata,CDate) VALUES ('$pname','$pdesc','$ftype','$fname', '$fdata', NOW() )";
$query = mysql_query($sql) or die(mysql_error());
echo "File Uploaded!";
} else
echo "File Too Large";
?>
and the page where the time difference is going to display:
<?php
$con = mysql_connect("localhost","ttt","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Date", $con);
$result = mysql_query("SELECT DATEDIFF('CDate','NOW()')");
echo "<table border='1', align='center'>
<tr width>
<th>poster_name </th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DDate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Is there any way to store the time difference to a row in mysql?
One more thing: the row type where the file time is recording now is set to timestamp
Pls answer me in the forum of php code so that i can understand my mistake very well..
Looking to hear more from all..
Thanks in Advance.
I am new to this Forum, and i really need help..because i stuck with a problem in php.
I am trying to learn php myself..now i am working with finding the difference of two time.
what am doing is that: I am uploading a file..when the submit button pressed..the current date and time of that will upload to my database automatically..Am using the Now() function to do so.
And when i am trying to find the difference between the file uploaded time and the current time the answer that am getting is 0.
but i want the answer like: If file uploaded time:2009-10-11 23:46:37
current time:2009-10-12 33:50:45
difference time: 1 day 10:04:08
Is that possible:
this is my code:
<?php
$db = mysql_connect("localhost","ttt","");
mysql_select_db("date");
$pname = $_REQUEST['pname'];
$time_now = date('Y-m-d H:i:s');
$pdesc = $_REQUEST['pdesc'];
$ftype = $_FILES['pfile']['type'];
$result = date("H:i:s",mktime(0,0,($currDate - $oldDate),0,0,0));
$fname = $_FILES['pfile']['name'];
if ($_FILES['pfile']['size'] <= $_REQUEST['MAX_FILE_SIZE'])
{
$fdata = fread(fopen($_FILES['pfile']['tmp_name'], "rb"),
$_FILES['pfile']['size']);
$fdata = base64_encode($fdata);
$sql = "INSERT INTO pictures (poster_name,pdesc,ftype,fname,fdata,CDate) VALUES ('$pname','$pdesc','$ftype','$fname', '$fdata', NOW() )";
$query = mysql_query($sql) or die(mysql_error());
echo "File Uploaded!";
} else
echo "File Too Large";
?>
and the page where the time difference is going to display:
<?php
$con = mysql_connect("localhost","ttt","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Date", $con);
$result = mysql_query("SELECT DATEDIFF('CDate','NOW()')");
echo "<table border='1', align='center'>
<tr width>
<th>poster_name </th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['DDate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
Is there any way to store the time difference to a row in mysql?
One more thing: the row type where the file time is recording now is set to timestamp
Pls answer me in the forum of php code so that i can understand my mistake very well..
Looking to hear more from all..
Thanks in Advance.