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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff Help

Status
Not open for further replies.

rbh123456789

Technical User
Mar 3, 2010
80
CA
CR 11.5

//MyFormula located in the Details section
DateDiff('y',{View_2.CLOSED},CurrentDate)

This formula calculates the difference between the two fields, and displays the results as a number.

When the MyForumla equals 365 and above, i want want Years to be displayed, followed by the days.
For example, if MyFormula = 370 then the display should be '1 Year 5 Days'. For 745 '2 Years 15 Days' etc.

Any ideas?
 
i think you would need to calculate the DateDiff using minutes, not years, then do the conversion into years within your formula for display.
 
numbervar diff := DateDiff('d',{View_2.CLOSED},CurrentDate);
totext(truncate(diff/365),0,"")+
(
if diff/365 >= 2 then
" Years" else
if diff/365 >= 1 then
" Year"
)+" "+
totext(diff-truncate(diff/365),0,"")+
(
if diff-truncate(diff/365) >= 2 then
" Days" else
if diff-truncate(diff/365) = 1 then
" Day"
)

I didn't test this, but I think it should work.

-LB
 
Thanks everyone. While waiting for the response i came up with my own method which seems to work too.

//Formula for Variables
shared numbervar Range year0:= 0 to 364;
shared numbervar Range year1:= 365 to 729;
shared numbervar Range year2:= 730 to 1094;

(if {@MyForumla} in year0 then totext({@MyForumla},0,"") else if {@MyForumla} in year1 then '1 Year ' & totext({@year1},0,"") else if {@MyForumla} in year2 then '2 Years ' & totext({@year2},0,"")) & ' Days';

//Forumula for @year1
{@MyForumla}-365

//Formula for @year2
{@MyForumla}-730

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top