Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I subtract a date field from another to show year,month,day? 2

Status
Not open for further replies.

nobody5170

Technical User
Feb 27, 2010
7
Hello everybody,I couldn't find my question in FAQs.I want to subtract a date field from another with datediff formula and display the difference in my report in year,month and day format.
THANKS
 
What exactly do you mean regarding the resulting format? Can you show a result for datediff and then show how you would expect it to be displayed?

-LB
 
when we want to calculate the years or months or days between start date & end date, we write:
DATEDIFF("Y"or"M"or"D",STARTDATE,ENDDATE)
now i want to display this difference in this format:how many years & how many months & how many days
for example:
start date: 2008/11/15
end date: 2009/12/20
the result is: 1 year & 1 month & 5 days
but what's the formula?
THANKS A LOT
 
Here's one way....maybe not the easiest....

3 Formulas (4 if you count the optional final display one to concatenate them)

(datedif is your date calc in DAYS)

1 find whole number of years
Code:
Global NumberVar Yrs := {@datedif}/365;
Truncate(Yrs)

2 find whole number of months (based on 30 day month)
Code:
Global NumberVar Mnths := ({@datedif} - {@ageyrs} * 365) / 30;
Truncate(Mnths)

3 find whole number of days
Code:
Global NumberVar Dys := ({@datedif} - ({@ageyrs} * 365)) - ({@agemths} * 30);
Truncate(Dys)

4 display
Code:
{@ageyrs} & ' Years and ' & {@agemths} & ' Months and ' &  {@agedays} & ' Days'


-- Jason
"It's Just Ones and Zeros
 
THANKS LB
SPECIAL THANKS JASON
surely it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top