Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: DateDiff Formula Post Reply Post New Topic
Author Message
VickiM
Newbie
Newbie
Avatar

Joined: 02 May 2011
Location: United States
Online Status: Offline
Posts: 28
Quote VickiM Replybullet Topic: DateDiff Formula
    Posted: 02 Jun 2011 at 7:56am

Hi.

Can you tell me why I am getting an error when trying to save this formula in Crystal Reports XI?
 
DateDiff("yyyy",{EMPLOYEE.DATE_HIRED},Now())+Int(Format(Now(),"mmdd")<Format({EMPLOYEE.DATE_HIRED},"mmdd"))
 
The message I'm getting says I have a ) missing.
Thanks!
VickiM
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Jun 2011 at 8:45am
can you explain what you are trying to get at with the formula?
I am confused by it as the datediff() is looking at years but you are using NOW which is time
also the INT and FORMAT are not making sense to me...
IP IP Logged
VickiM
Newbie
Newbie
Avatar

Joined: 02 May 2011
Location: United States
Online Status: Offline
Posts: 28
Quote VickiM Replybullet Posted: 02 Jun 2011 at 10:06am

I'm trying to figure Tenure using the person's date of hire.  It works in Access.

I'm getting an error stating: The ) is missing. The first occurrence of the word Format is highlighted so I think it means I need a ) somewhere around that word.  However, no matter where I put one, I get the same message.
 
Thanks!
VickiM
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 02 Jun 2011 at 10:17am

so you want the number as years hired including this year if the hire date was before or on today but not this year if it was after today?

I think this would give you that...
DateDiff('yyyy',{EMPLOYEE.DATE_HIRED},currentdate) - if datepart('y',currentdate)>datepart('y',{EMPLOYEE.DATE_HIRED}) then 1
IP IP Logged
VickiM
Newbie
Newbie
Avatar

Joined: 02 May 2011
Location: United States
Online Status: Offline
Posts: 28
Quote VickiM Replybullet Posted: 06 Jun 2011 at 10:28am
Thank you!  That works.  However, I need it to use the month and day as well as the year to figure the tenure. So if they started on 10/1/2009 and today is 6/6/2011 it should show 1 year because they won't actually have been there 2 years until October.  When I type in mmddyyyy in each of the places that have either yyyy or just a y, I get an error that says it's out of range.  Can you tell me why?  Thanks so much!
VickiM
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Jun 2011 at 11:59am

the second half of the formula is supposed to handle looking at today's date and making sure it has been one full year...try this one:

DateDiff('yyyy',{EMPLOYEE.DATE_HIRED},currentdate)
-
if datepart('y',currentdate)>=datepart('y',{EMPLOYEE.DATE_HIRED}) then 0 else 1
IP IP Logged
VickiM
Newbie
Newbie
Avatar

Joined: 02 May 2011
Location: United States
Online Status: Offline
Posts: 28
Quote VickiM Replybullet Posted: 08 Jun 2011 at 3:27am
That's perfect!  Thank you very much!!!
VickiM
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.