Jump to content

View All Date Diffrence


Go to solution Solved by Barand,

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/292348-view-all-date-diffrence/
Share on other sites

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

  • Solution

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 by Barand

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.