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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving a date value from a string

Status
Not open for further replies.

Oscar115

Technical User
May 21, 2010
30
US
I have been asked to retrieve a date value from a string db field, field name is {HCOMMENT.CLOB}

A sample string value looks like the following:
LEASE APPT SCHEDULE BY PHONE / APPT IS FOR 2/17/2010 2:30PM.

I am attempting to get the date 2/17/2010 from this string.

I have defined the following using lookslike and am not getting any values back, note {wlcerti.dissuedate} is a datetime field.

if lookslike({HCOMMENT.CLOB},"?/?/??") then
date({wlcerti.dissuedate})
else
if lookslike({HCOMMENT.CLOB},"?/?/????") then
date({wlcerti.dissuedate})
else
if lookslike({HCOMMENT.CLOB},"?/??/??") then
date({wlcerti.dissuedate})
else
if lookslike({HCOMMENT.CLOB},"?/??/????") then
date({wlcerti.dissuedate})
else
if lookslike({HCOMMENT.CLOB},"??/??/??") then
date({wlcerti.dissuedate})
else
if lookslike({HCOMMENT.CLOB},"??/??/????") then
date({wlcerti.dissuedate})

I am certain that the date I am trying to pull from the string is a value in the db field wlcerti.dissuedate

Thanks!
 
I have not used this function before, but looking at the help for it. I think you would want to start and end each compare with an "*", i.e., if lookslike({HCOMMENT.CLOB},"*?/?/??") then date({wlcerti.dissuedate}).

Also I that with a little creative thought you might be able to reduce the number of 'if's you are using.
 
What is the logic here? It sounds like you are saying if there is any date in the string, show the {wlcerti.dissuedate}.

Here's one way to get the date out:

stringvar x := {table.string};
stringvar array y := split(x," ");
numbervar i;
numbervar j := ubound(y);
datevar n := date(0,0,0);
for i := 1 to j do(
if isnumeric(y[1]) and
not(":" in y) then
if date(y) <> date(0,0,0) then
n := date(y)
);
n

-LB
 
lbass,
You are correct, I do not want to return {wlcerti.dissuedate} but rather the date within the string.

I have tried as you have suggested but am receiving an error "Bad Date format string" for date(y) when refreshing the report.

Any suggestion for getting past this?

I do appreciate your direction.

Thanks
 
I have modified your suggestion and have received the results I was hoping for.

I have changed it as follows:

stringvar x := {HCOMMENT.CLOB};
stringvar array y := split(x," ");
numbervar i;
numbervar j := ubound(y);
datevar n := date(0,0,0);
for i := 1 to j do(
if isnumeric(y[1]) and
not(":" in y) then
if isdate(y) = True then
n := date(y));
n

Thanks for your help!!
Oscar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top