Jump to content

View All Date Diffrence


I-AM-OBODO

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

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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.