Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Filter # from a 'Date to Number Format' formula Post Reply Post New Topic
Author Message
aquestion4u
Newbie
Newbie


Joined: 12 Jul 2013
Location: United States
Online Status: Offline
Posts: 4
Quote aquestion4u Replybullet Topic: Filter # from a 'Date to Number Format' formula
     Posted: 06 Aug 2013 at 5:07am
I have used the following formula to change a string (DOB) to date format:
 
date(tonumber(left({person.date_of_birth},4)),tonumber(mid({person.date_of_birth},5,2)),tonumber(right({person.date_of_birth},2)))
 
After changing to a date format, I was then able to use the difference between the current date and DOB to compute Curr Age, which is a number format:
 
datediff('yyyy',{@DOB},currentdate)-(if datepart('y',currentdate)>datepart('y',{@DOB}) then 0 else 1)
 
PROBLEM:
 
I am trying to filter out all Curr Age>= 18, but I keep getting the following error:
 
The string is non-numeric and the formula editor highlights the (tonumber(left({person.date_of_birth},4)) part in the formula below, which is the same one above:
 
date(tonumber(left({person.date_of_birth},4)),tonumber(mid({person.date_of_birth},5,2)),tonumber(right({person.date_of_birth},2)))
 
Can someone please help and let me know what I need to change/add to fix this?  Thank you so much.
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2013 at 5:23am
what does your raw data look like?

Edited by DBlank - 06 Aug 2013 at 5:23am
IP IP Logged
aquestion4u
Newbie
Newbie


Joined: 12 Jul 2013
Location: United States
Online Status: Offline
Posts: 4
Quote aquestion4u Replybullet Posted: 06 Aug 2013 at 5:40am
Date of Birth = String
YYYYmmdd, e.g., 19630322
 
Current Date is just 'currentdate'
 
 
Thanks.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2013 at 7:07am
have you looked for bad data in your source like alpha numeric items not exactly 8 characters long?
you can filter on
not (isnumeric(dob))
or len(dob) <> 8
to look for things some bad data
 
if you have bad data what do you want to do with it?
exclude it? zero it out? something else?
 
If you have some
IP IP Logged
aquestion4u
Newbie
Newbie


Joined: 12 Jul 2013
Location: United States
Online Status: Offline
Posts: 4
Quote aquestion4u Replybullet Posted: 06 Aug 2013 at 7:15am
Thank you I'm all set as I figured it out and it's working perfectly now!  Thanks!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Aug 2013 at 7:17am

Thumbs%20Up

if you get a chance please post your solution for others

IP IP Logged
aquestion4u
Newbie
Newbie


Joined: 12 Jul 2013
Location: United States
Online Status: Offline
Posts: 4
Quote aquestion4u Replybullet Posted: 06 Aug 2013 at 9:43am
I used the following approach and got what I needed:
 

CONVERT DOB STRING TO NUMBER & COMPUTE AGE:

 

Date of Birth =

Mid ({person.date_of_birth},5 ,2 )+ "/" + Mid ({person.date_of_birth},7 ,2 )+ "/"+ Mid ({person.date_of_birth},1 ,4 )

 

Convert DOB =

local stringvar tcdate;

tcdate :={person.date_of_birth};

date(val(tcdate[1 to 4]),val(tcdate[5 to 6]),val(tcdate[7 to 8]))

 

Age =

INT ( (CurrentDate-{@Convert DOB})/365)
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