Jump to content


Photo

PHP date difference


  • Please log in to reply
2 replies to this topic

#1 adyre

adyre
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 22 May 2006 - 08:02 PM

I have something like this:

<?
$sql = mysql_query("SELECT data, DATE_SUB(data, INTERVAL 20 DAY) - CUR_DATE() as DATAX");
while($row = mysql_fetch_array($sql)){
print $row['datax'];
}
?>

And it displays somethink like 90 days even if 'data' is the current date......

If any of you can help, please do that.....

Or any other method so I can display how many days remaining until "data" its 20 days old.

I delete them automaticaly if they reach 20 days, but I can't post "X days remaining"...

Excuse my English, but I'm from Romania...


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 22 May 2006 - 08:18 PM

SELECT (20 - (TO_DAYS(CURDATE()) - TO_DAYS(data))) AS datax

or

SELECT (TO_DAYS(data) + 20 - TO_DAYS(CURDATE()) ) AS datax

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 adyre

adyre
  • Members
  • Pip
  • Newbie
  • 8 posts

Posted 22 May 2006 - 09:52 PM

It works perfect... Thanks very much... You don't even know how much you helped me... I've tried so much to figure this out and I haven't found a solutin... 10x





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users