Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Showing years of service Post Reply Post New Topic
Author Message
gooker
Newbie
Newbie
Avatar

Joined: 29 Mar 2011
Online Status: Offline
Posts: 11
Quote gooker Replybullet Topic: Showing years of service
     Posted: 20 Dec 2011 at 4:40am
I am trying to create a demographic census for insurance reporting purposes and I need to create a calculation field that would show the hire date as years of service effective on the run date of the report. I would like to show all years, months and days. Being a newbie, I have no clue as to how to get here.
G
Gooker
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Dec 2011 at 8:19am
I would try:
local numbervar d := datediff("d", {table.hireDate}, currentDate);
local datetimevar dt:= cdate(d);
dt := DateAdd("y",-1900, dt);
dt
 
 
this calculates the days of service, then computes the date starting at dec 31, 1899.  subtracting 1900 years would give the years of service.
 
Hope it works...not sure about CR and dates with years close to 0...never done it myself.
 
HTH
IP IP Logged
comatt1
Senior Member
Senior Member
Avatar

Joined: 19 May 2011
Online Status: Offline
Posts: 337
Quote comatt1 Replybullet Posted: 21 Dec 2011 at 2:21am

Usually try something determining date ranges with -- dateserial function, but sure lock's works fine

IP IP Logged
gooker
Newbie
Newbie
Avatar

Joined: 29 Mar 2011
Online Status: Offline
Posts: 11
Quote gooker Replybullet Posted: 21 Dec 2011 at 2:32am
Originally posted by lockwelle



I would try:
local numbervar d := datediff("d", {table.hireDate}, currentDate);
local datetimevar dt:= cdate(d);
dt := DateAdd("y",-1900, dt);
dt
 
 
this calculates the days of service, then computes the date starting at dec 31, 1899.  subtracting 1900 years would give the years of service.
 
Hope it works...not sure about CR and dates with years close to 0...never done it myself.
 
HTH


OK, I tried it and it didn't work, it just created a weird date and time
G
Gooker
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Dec 2011 at 3:27am
well, I would see what sort of date/time it created vs what the known amount of service should be, and then tweaking the formula until you get the value that you are after.
 
...perhaps, I have some values backwards in the datediff, I never remember how they work and use examples to make sure that I am getting a value that makes sense.
 
Just a thought, the goal of the DateDiff part is to determine the difference in days between 2 dates.  Cdate will convert the number of days to a calendar date, which will have year, month, and date.  Subtract the constant year, which i think is 1900, and you will have...a weird date.
 
what might be missing is something like:
yr := YEAR(dt) - 1900;
mn :=MONTH(dt);
dy := DAY(dt);
 
those are the values that you are after...see if they are close.
IP IP Logged
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