-1

I've tried looking around the web but didn't find enough info to convert end date field into time remaining.

Right now I have this code:

echo '
<tr>
   <td style="background: #f0f0f0;" width=50% align=center>'.$row['end_date'].'</td>
</tr>';

which shows a value end_date from sql. However, I need to use Time left instead, so to convert it into x days x hours x minutes x seconds left. The date itself looks like this: 2017-02-08 20:52:20

Could anyone help me out, please?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
ZeroFun
  • 23
  • 4
  • 2
    Your question appears to have nothing to do with SQL so I removed that tag. – Gordon Linoff Feb 07 '17 at 13:21
  • What have you tried thus far in formatting the date as you desire it? http://stackoverflow.com/help/mcve – Neo Feb 07 '17 at 13:28
  • have you tried TIMEDIFF()? – Bernhard Feb 07 '17 at 13:29
  • I've tried this tutorial: http://stackoverflow.com/questions/7474762/php-get-how-many-days-and-hours-left-from-a-date but it provides only daysa nd hours, no minutes and seconds. Also whenever I tried inserting the echo inside the website gave me 500 error. – ZeroFun Feb 07 '17 at 13:32
  • I haven't tried TIMEDIFF(). Thank you for suggestion. Going to try it now. – ZeroFun Feb 07 '17 at 13:33
  • '.TIMEDIFF("$row['full_address']","NOW()").' gave me 500 error... – ZeroFun Feb 07 '17 at 13:38
  • You need to take the code in the duplicate question and expand upon it. Just because it is slightly different doesn't mean it isn't useful. If you have any problems, post the code you wrote and what error you get and then we can try to help you. – John Conde Feb 07 '17 at 14:59

2 Answers2

0

Check out the date/time functions, especially date_diff(). The example on that page does what you're looking for, I think.

alanlittle
  • 460
  • 2
  • 12
0

I solved it this way:

$datetime1 = date_create('now');
$datetime2 = date_create($row['end_date']);
$interval = date_diff($datetime1, $datetime2);
echo '
<tr>
<td style="background: #f0f0f0" width=50% align=center>'.$interval->format('%a days %h hours %i min %s sec').'</td>
</tr>';
ZeroFun
  • 23
  • 4