converting days to year, month and days

Hi shivakumarpatil,

I need to convert 1978 days into years, month and days.

can you some more information please? What's the output you want, ...
 
hi kenny.willems,

say carrer start date = 18/12/2003 (ie 8th dec 2003)
so till date i have 1978 days .
how i got is (18/12/2003 - today).

Now i want to convert 1978 days into certain years, months and remaining days,

say 5 years, 5 months, 1 day..

TIA
Shiva
 

leite1969

New Member
def var dt-data as date no-undo format "99/99/9999" column-label "Data".
def var i-dias as integer no-undo column-label "Dias".
def var i-mes as integer no-undo column-label "Mês".
def var i-ano as integer no-undo column-label "Ano".

assign dt-data = 12/08/2003
i-dias = (today - dt-data)
i-ano = i-dias / 365
i-mes = (i-dias - (i-ano * 365)) / 30
i-dias = i-dias - (i-ano * 365) - (i-mes * 30).

disp dt-data
i-dias
i-mes
i-ano.
 
You need to decide on the limitations you are prepared to accept.

A generic 'year = 365 days, months = 30 days' algorithm will only give a rough approximation.

An 'exact' method needs a start date, as well as catering for leap years, days in months, etc.
 
Thanks leite1969,

but i am getting 5 years, 5 months and 3 days.

is it b'cos we are considering days in a month = 30.

so now how do i find the exact days.
actually it should be 5 years, 5 months and 1 day as on today.

TIA,
Shiva
 
You need to decide on the limitations you are prepared to accept.

A generic 'year = 365 days, months = 30 days' algorithm will only give a rough approximation.

An 'exact' method needs a start date, as well as catering for leap years, days in months, etc.

Also: how do you define when a 'month' has passed?
 

Casper

ProgressTalk.com Moderator
Staff member
Maybe something like:
Code:
DEFINE VARIABLE dStart AS DATE        NO-UNDO.
DEFINE VARIABLE dEnd AS DATE        NO-UNDO.
DEFINE VARIABLE dMonth AS DATE        NO-UNDO.
DEFINE VARIABLE dDay AS DATE        NO-UNDO.
ASSIGN dStart = DATE(12,8,2003)
       dEnd = TODAY.
 
ASSIGN dMonth = IF MONTH(dStart) > MONTH(dEnd)
                THEN DATE(MONTH(dStart),DAY(dStart),YEAR(TODAY) - 1)
                ELSE DATE(MONTH(dStart),DAY(dStart),YEAR(dEnd))
       dDay = IF DAY(dStart) > DAY(dEnd)
              THEN DATE(MONTH(dEnd) - 1 ,DAY(dStart),YEAR(dEnd))
              ELSE DATE(MONTH(dEnd),DAY(dStart),YEAR(dEnd)).
 
MESSAGE 'Year:' + STRING(INTERVAL(dEnd,dStart,'year'))
        'Month:' + STRING(INTERVAL(dEnd,dMonth,'month'))
        'Day: ' + STRING(INTERVAL(dEnd,dDay,'day'))
    VIEW-AS ALERT-BOX INFO BUTTONS OK.

And since today isn't over I think it should be 5 year 5 months and 0 days :)

Casper.
PS I didn't test this thoroughly but it seems to be allright
 

tamhas

ProgressTalk.com Sponsor
If you have a start date, then simply add the number of days to that to give you the actual end date and then use arithmetic like Casper used to compare the year, month, and days of the two dates.

Frankly, it seems like a rather arbitrary statement since the end date is quite precise and the count of years, months, and days rather vague because of the variability of the year and month. I.e., with two different starting dates, you are going to get two different year, month, and day counts using the same interval. That's not likely to be intuitive to anyone.
 
Top