-1

I have a foreach running through each set of project records and placing them into a table, and I need one column to display the number of days until the project is due based on the current time. It currently just displays as a timestamp value and I can't find a working way to convert it into a rounded number of days. Any help appreciated.

<td><?= time() - $project['project_duedate'] ?></td>

Output of above code would just be for example: 38051935

jccoder
  • 111
  • 7
  • Does this answer your question? [Finding the number of days between two dates](https://stackoverflow.com/questions/2040560/finding-the-number-of-days-between-two-dates) – El_Vanja May 10 '21 at 10:07
  • @El_Vanja It doesn't seem to unfortunately. – jccoder May 10 '21 at 10:13
  • And how exactly? Which part of it doesn't fit your requirements? As far as I can see, you're subtracting two timestamps and the accepted answer does the exact same thing. If you need something different, then please edit the question to show what you've tried and explain why it isn't what you're looking for on some sample values. – El_Vanja May 10 '21 at 10:15
  • Aside from the accepted answer, which has some flaws listed in the comments, there are plenty of other answers there advocating to use `DateTime` for this (which you really should). – El_Vanja May 10 '21 at 10:18
  • "Timestamp" is one of those words that means several things. The specific way to do date maths depends on the specific format you have. You say "table", so I suspect there's a relational database involved. If that's the case, it's very likely you have strings like `2021-05-10`. You cannot do maths with text, you need to convert to a usable format. – Álvaro González May 10 '21 at 10:18
  • @El_Vanja New to PHP apologies, I had started my opening script as = as supposed to – jccoder May 10 '21 at 10:22
  • The timestamp you have above is the number of seconds between 'now' and the project due date. If you just want the number of days, you just need to do some division to convert the seconds to minutes, to hours, to days - right? – DanLewis May 10 '21 at 10:24
  • @ÁlvaroGonzález I got it sorted using the originally linked post, I just can't upvote to say it worked now. Thank you anyway. – jccoder May 10 '21 at 10:24
  • @DanLewis All sorted now yeah, rookie PHP error lead me to believe it was an older method that wasn't working! Thanks anyway. – jccoder May 10 '21 at 10:25

1 Answers1

0

Can't upvote the commenting linking originally so had to manually post the answer from there.

$now = time(); // or your date as well
$your_date = strtotime("2010-01-31");
$datediff = $now - $your_date;

echo round($datediff / (60 * 60 * 24));
jccoder
  • 111
  • 7