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

Using DateDiff

Status
Not open for further replies.

Ajith2002

Programmer
Jul 16, 2002
30
US

hi

am trying to use datediff() function to get the diff between two days in 'days'. i am getting the diff in decimals. like, if the diff between two dates is 3 days, the function will return 3.00

I dont want that .00
How to eliminate that ? I tried all possible functions, but didnt succeed.

Pls help!!
Thanks very much.
 
That is the format, not the formula. Click on the numbers in preview and use the toolbar buttons to remove the decimals. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Well, I am appending the result with a string in a formula. If it is just the diff bet two dates, we can very well change the format like how u said.

This is what am trying to do -

dateTimeVar d1 := Date({Query.Creation Time});
dateTimeVar d2 := CurrentDateTime;
numberVar age;

stringVar ageDays;

age := DateDiff("d",d1,d2) - DateDiff("ww",d1,d2,crSaturday) - DateDiff("ww",d1,d2,crSunday);


(
If age = 1 Then
ageDays := "1 Day"
Else If age = 0 Then
ageDays := "1 Day"
Else
ageDays := age & " Days"; // This returns "2.00 Days" if ageDays = 2
)
 
Ah - you left that nugget of information off your initial post.

After you assign the value to "age", enter:

StringVar AgeConvert := ToText(age,0);

Then turn your last line into:

ageDays := AgeConvert & " Days";


Naith
 
If you use the & to concatenate a number you have no control of the format. Use ToText to convert the number to text, and then you have the ability to remove the decimals:

ToText( {field} , 0 ) Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top