php - Days Until Date

874

So in my database, I have "due" and a date.

It is defined like this:$dues[$index] = $row["due"];

I want toecho how many days until that date, I have looked around but can't seem to find it from a database.

786

Answer

Solution:

In the database, you have a due and a date field. What's in the date field? Today's date? Pretty sure you don't even need that there and can just use today's date with php to calculate and echo the days until that date without even changing the database.

Since you already stored all your due values inside of the dues array, you can just echo in a table:

$array_size = count($dues);
echo '<table>';
for($i = 0; $i < $array_size; $i++) {
    // if your date is in the format mm/dd/yyyy...
    // (you can change it however you want according
    // to how you formatted it in your database).
    $today = date('m/d/Y');
    $daysuntil = (strtotime($dues[$i])-strtotime($today)) / 86400;
    echo '<tr><td>Due: '.$dues[$i].'</td>';
    echo '<td>'.$daysuntil.' days left</td></tr>';
}
echo '</table>';

People are also looking for solutions to the problem: php - Try to install the Laravel 5.5. It's showing the OpenSSL certificate error

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.