Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Crystal DateDiff function Post Reply Post New Topic
Author Message
Jul747
Newbie
Newbie


Joined: 24 Jan 2014
Online Status: Offline
Posts: 5
Quote Jul747 Replybullet Topic: Crystal DateDiff function
    Posted: 24 Jan 2014 at 9:59am
I'm using Crystal Reports 11.  I created a new function and trying to find the number of days between two dates.  What I'm getting in the result is a decimal... 4.00    I want to see 4, not 4.00
Here's my formula:
 
DateDiff("d", {Command.RESERVATION_START_DATE}, {Command.RESERVATION_END_DATE})+1
 
The variable names in the function are datetime, but I only want the # of days in integer form, not decimal.
 
I know the "d" should return the # of days between the dates, but it's not working for some reason (at least its not coming in the format I want...Integer.  I've tried INT and ToNumber in front of DateDiff, but no go.
The Reservation_start_date = 9/14/2013, end_date = 9/17/2013 and I want the result to be 4 because the reservation actually starts on 9/14... so the count would be 4...14,15,16,17  (and that's why I added + 1 on the end, otherwise I get 3. 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 24 Jan 2014 at 12:35pm
have you set the format of the formula...you know right click on the formula on the report and the change the number of decimals?

By default, CR shows all numbers with 2 decimal places. Datediff returns a numbers, so this should fix it
IP IP Logged
kostya1122
Senior Member
Senior Member
Avatar

Joined: 13 Jun 2011
Online Status: Offline
Posts: 475
Quote kostya1122 Replybullet Posted: 24 Jan 2014 at 1:53pm
or
totext(DateDiff("d", {Command.RESERVATION_START_DATE}, {Command.RESERVATION_END_DATE})+1,0,"")
IP IP Logged
Jul747
Newbie
Newbie


Joined: 24 Jan 2014
Online Status: Offline
Posts: 5
Quote Jul747 Replybullet Posted: 25 Jan 2014 at 11:04am
I did a right-click on the formula on the report and clicked on Format Text...
I get a 5-tabbed window come up and there's nothing showing where you can change the number of decimals. The named tabs are:
 
Common
Border
Font
Paragraph
Hyperlink
 
Is there anywhere else I can look to change the number of decimals in the formula?  It's just not in any of those tabs, looked high and low for it... 
IP IP Logged
Jul747
Newbie
Newbie


Joined: 24 Jan 2014
Online Status: Offline
Posts: 5
Quote Jul747 Replybullet Posted: 25 Jan 2014 at 11:05am
Thanks, but didn't work. Editor says something wrong with the function.
IP IP Logged
lolly54
Groupie
Groupie
Avatar

Joined: 25 Sep 2011
Online Status: Offline
Posts: 58
Quote lolly54 Replybullet Posted: 26 Jan 2014 at 10:49pm
Like kostya1122 suggested, ToText function should do the work for you.

Try...
ToText(DateDiff("d", {Command.RESERVATION_START_DATE}, {Command.RESERVATION_END_DATE})+1, 0)

Here's a link I found quite useful for ToText
http://crystaltricks.com/wordpress/?p=149
IP IP Logged
Jul747
Newbie
Newbie


Joined: 24 Jan 2014
Online Status: Offline
Posts: 5
Quote Jul747 Replybullet Posted: 27 Jan 2014 at 2:29am
thank you... your were correct except for the "" at the end, didn't need.
Thanks again for your time!
IP IP Logged
Jul747
Newbie
Newbie


Joined: 24 Jan 2014
Online Status: Offline
Posts: 5
Quote Jul747 Replybullet Posted: 27 Jan 2014 at 2:30am
kostya1122 was close.  Didn't need the "" at the end.
What you provided was dead on.  Thank you all very much for your time!
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.