I-AM-OBODO Posted November 7, 2014 Share Posted November 7, 2014 Hi all.How can i see all the difference between two dates in a column. I know to see a single date difference we can do:$stmt = $pdo->query("SELECT DATEDIFF(date_paid, next_due) AS diffdate FROM table_name");while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['diffdate'];}but i want all the difference to show in a table along with other details.thanks Quote Link to comment https://forums.phpfreaks.com/topic/292348-view-all-date-diffrence/ Share on other sites More sharing options...
Psycho Posted November 7, 2014 Share Posted November 7, 2014 Your question is vague. What do you mane show "all the difference between two dates in a column"? Give an example of a small set of data and what the expected output would be. Quote Link to comment https://forums.phpfreaks.com/topic/292348-view-all-date-diffrence/#findComment-1496054 Share on other sites More sharing options...
I-AM-OBODO Posted November 7, 2014 Author Share Posted November 7, 2014 Your question is vague. What do you mane show "all the difference between two dates in a column"? Give an example of a small set of data and what the expected output would be. sorry if you dont get me right. i have a table that has a transaction date and expiry date. I want to create another column where i can see the intervals between the order date and expiry date. i want to see them without doing a where clause. example Name Date Paid Expiry Date Date Difference John 2014-11-07 2014-12-01 24 days Doe 2014-11-07 2014-11-10 3 days This is what i did $stmt = $pdo->query("SELECT DATEDIFF(date_paid, next_due) AS diffdate FROM ca_payment"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo $row['diffdate']; } but its showing the total sum of date difference of all the column which is not what i want Quote Link to comment https://forums.phpfreaks.com/topic/292348-view-all-date-diffrence/#findComment-1496056 Share on other sites More sharing options...
Solution Barand Posted November 7, 2014 Solution Share Posted November 7, 2014 (edited) Are you sure you posted the query that is giving that result? mysql> SELECT name -> , date_paid -> , expiry_date -> , DATEDIFF(expiry_date, date_paid) as diff -> FROM test_chidi; +------+------------+-------------+------+ | name | date_paid | expiry_date | diff | +------+------------+-------------+------+ | John | 2014-11-07 | 2014-12-01 | 24 | | Doe | 2014-11-07 | 2014-11-10 | 3 | +------+------------+-------------+------+ edit: where does next_due come from - you don't mention that in your data? Edited November 7, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/292348-view-all-date-diffrence/#findComment-1496058 Share on other sites More sharing options...
I-AM-OBODO Posted November 7, 2014 Author Share Posted November 7, 2014 Are you sure you posted the query that is giving that result? mysql> SELECT name -> , date_paid -> , expiry_date -> , DATEDIFF(expiry_date, date_paid) as diff -> FROM test_chidi; +------+------------+-------------+------+ | name | date_paid | expiry_date | diff | +------+------------+-------------+------+ | John | 2014-11-07 | 2014-12-01 | 24 | | Doe | 2014-11-07 | 2014-11-10 | 3 | +------+------------+-------------+------+ edit: where does next_due come from - you don't mention that in your data? I wonder what's wrong with me. I've seen the problem. Thanks my head was beclouded thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/292348-view-all-date-diffrence/#findComment-1496059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.