# Thread: How to get years, months and days from two dates

1. Registered User
Join Date
Jan 2003
Posts
1,634

## Unanswered: How to get years, months and days from two dates

Hi,
I would like to get how many years, months and days is between two dates.

I have written:
Code:
`db2 values days(date('2008-08-31'))-days(date('2008-01-01'))`
the result is: 243 days.

How to get from this result how many years, months and days have elapsed from first to second date.
Regards,
Grofaty

2. Registered User
Join Date
Feb 2008
Location
Japan
Posts
3,483
Code:
```------------------------------ Commands Entered ------------------------------
values date('2008-08-31')-date('2008-01-01');
------------------------------------------------------------------------------

1
----------
730.
yyyymmdd

1 record(s) selected.```
Please note 2nd to 4th rows of the following results.
Code:
```------------------------------ Commands Entered ------------------------------
SELECT to_date, from_date
, DAYS(to_date) - DAYS(from_date) AS "days"
, to_date - from_date             AS " yyyymmdd"
FROM (VALUES ( DATE('2008-08-31'), DATE('2008-01-01') )
, ( DATE('2009-03-01'), DATE('2009-02-01') )
, ( DATE('2008-03-01'), DATE('2008-02-01') )
, ( DATE('2008-04-01'), DATE('2008-03-01') )
) data(to_date, from_date);
------------------------------------------------------------------------------

TO_DATE    FROM_DATE  days         yyyymmdd
---------- ---------- ----------- ----------
2008-08-31 2008-01-01         243       730.
2009-03-01 2009-02-01          28       100.
2008-03-01 2008-02-01          29       100.
2008-04-01 2008-03-01          31       100.```

3. Registered User
Join Date
Jan 2003
Posts
1,634