Here my query :
$sql = "SELECT TIMESTAMPDIFF AS diff( DAY, (SELECT date_expire FROM tbl_rec), now())";
$query = mysql_qery($sql);
I need a return that will be an array in php while.
Please help.
The query is just:
$sql = "SELECT TIMESTAMPDIFF AS diff( DAY, (SELECT date_expire FROM tbl_rec), now())";
and you can generate the array like so (assuming you are using MySQL):
$time= array();
$result = mysql_query($sql);
while(($row = mysql_fetch_assoc($result))) {
$time= $row['diff'];
}
Use TIMEDIFF
to get the difference between 2 times
$query = "select timediff(date_expire, now()) diff
from tbl_rec;";
$rs = mysql_query($query);
$row = mysql_fetch_assoc($rs);
echo $row['diff'];
Use the below query for date difference.
SELECT DATEDIFF(CURDATE(),date_add) as diff FROM `Table_name`;
i.e, to get date difference only. So for your table see the query below
$sql = "SELECT DATEDIFF(CURDATE(),date_expire) as diff FROM `tbl_rec`;
$query = mysql_query($sql,$connection);
To see the output, first run the sql query in your mysql admin or in command prompt.
SELECT DATEDIFF(CURDATE(),date_expire) as diff FROM `tbl_rec`;