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!

Years of Service formula error 3

Status
Not open for further replies.

neronikita

Technical User
Feb 20, 2002
159
US
Good morning!

I am trying to use the following formula in Crystal 2008.

(CurrentDate - {Employee.DOH}) /365.25

Employee.DOH is in the date format.

It is telling me it needs a number at the employee.DOH field. no matter what I try to convert it to, it just tells me that it needs to be some kind of number or date. I'm not sure what the problem is and I'm a little rusty on my Crystal formulas. I can't figure out what it really wants from me.

I am using SQL Server 2008 for my database.

Thanks,

Di
 
Also DateDiff is an easier way to get a difference in years, among other functions. Use HELP to get the basics and experiment a bit till you're familiar with it. Saves a lot of time once you know.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 11.5 with SQL and Windows XP [yinyang]
 
Thanks to both of you. I used to know this stuff years ago, but it's been a while since I worked with it. The cDate worked, and I will play with DateDiff.

Thanks again!

Di
 
Quick question -

I have two formulas calculating two different Years of Service dates for employees who have worked here more than once. When I do a third formula to add them together, it only adds the ones with two formulas (and not all employees have two sets of dates) so the employees who only worked here once do not show anything. Any thoughts on why it only shows when there are two sets of dates?

Thanks,

Di
 
Please show the contents of both formulas. It sounds like you have fields that can be null, e.g., history fields, so you would have to do a check for this.

-LB
 
Formulas are:

oldYOS
((cdate({Employee.PreviousDOT})-cdate({Employee.PreviousDOH}))/365.25)

YOS
((CurrentDate - cDate({Employee.CurrentDOH})) /365.25)

TotalYOS
({@oldyos} + {@yos})

Yes, the previousDOT and PreviousDOH allow nulls.

Thanks,

Di
 
Change the first formula to:

if isnull({Employee.PreviousDOT}) or
isnull({Employee.PreviousDOH}) then
0 else
(cdate({Employee.PreviousDOT})-cdate({Employee.PreviousDOH}))/365.25

-LB

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top