At this time I am unable to do this in the database. Our usage must occur in Cognos.
I'm having trouble find much detail on this function. Can you provide example syntax?
Main Topics
Browse All TopicsI am using Cognos. I have a field in my database that stores a date that I need to pull. The problem is that this is a text field.
Here is a sample contents: referred 2/2/2008. Or, sometimes the date is a little different, like "referred 2/2/08". Rarely, there is additional text in the field.
So my question is this: how can I parse this text to pull out the date in Cognos? Right now I have a prompt page with a start date and ending date on a different date field, but I need to convert these to this other field. Any ideas?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It would help if we knew what kind of database you're working with. However, there are cognos functions that will work too.
This gets you the two characters preceeding the first /:
substring([myDate],Positio
This gets you the characters between the /:
substring([myDate],Positio
This gets you the two characters following the second /:
substring([myDate],positio
Put 'em all together:
_make_timestamp(
cast(substring([myDate],Po
cast(substring([myDate],Po
cast(substring([myDate],po
Of course, this will throw an error if any of your fields have fewer then two /, or have a non-numberic in the two spaces before the first slash or after the second, or if any of them aren't in year/month/day format or contain invalid numbers. Other then that, it's bulletproof.
As Rwrigley pointed out in his earlier posts there are a number of issues here. Besides the ones he already pointed out the most problamatic from your point of view is the year being either 2 or 4 digits. This will not throw an error but will give you corrpt data. If you really have to attempt this I would first extract each piece into its own data item.
Once you have done that you can clean up each item before converting them to a number. ONce you have cleaned each section you should be able to convert to a date without errors. Here is an example of some possible clean up for the first part.For example
Define date_Part_1 =
substring ([Referral_Auth_Notes],Pos
Then Define Data_Part_1_Clean
IF ( [date_Part_01] = '01' or [date_Part_01] = ' 1' or [date_Part_01] = '1 ') THEN ( '01' ) ELSE
IF ( [date_Part_01] = '02' or [date_Part_01] = ' 2' or [date_Part_01] = '2 ') THEN ( '02' ) ELSE
IF ( [date_Part_01] = '03' or [date_Part_01] = ' 3' or [date_Part_01] = '3 ') THEN ( '03' ) ELSE
.
.
.
IF ( [date_Part_01] = '09' or [date_Part_01] = ' 9' or [date_Part_01] = '9 ') THEN ( '09' ) ELSE
( '00' )
Thanks for all your help so far. I should have thought of that typo, especially considering I just recently had to deal with that.
I'm still getting an error.
DPR-ERR-2082 An error has occurred. Please contact your administrator. The complete error has been logged by CAF with SecureErrorID:2008-12-02-1
The log file is attached.
Hmmm I substituted a field from one of my pakages and it works fine. Try this create a new report(do not reuse the report you have been working on). Bring two items into the report a key field and Referral_Auth_Notes. Filter the report so you get one record that has a date in Referral_Auth_Notes. Drag a new Query calculationquery calculation into the report after Referral_Auth_Notes and name it Date_Part_1. Copy and past the calculation below into the expression editor. Run the report.
If ( [Referral_Auth_Notes] <> null) then (substring ([Referral_Auth_Notes],pos
Modified from above comment by Rwrigley
2md part
If ( [Referral_Auth_Notes] <> null) then
substring([Referral_Auth_N
3rd part
If ( [Referral_Auth_Notes] <> null) then
substring( [Referral_Auth_Notes],posi
You have to create the three variables separately and then put them together because your data is so diverse. You will also have to dedide what to do with the dates that are missing.
So once you have created three variables Date_Part1, Date_Part2, and Date_Part3. You will need to clean them up. Ie remove any that are not numbers or are null. See the code I posted above for Date_Part_clean. For month you will need to check for 1 - 12 for day 1-31 and for year well you get the idea.
Only once you have eliminated any non-nummeric or invalid characters can you glue the pieces together and do a cast to make it a date.
Also I noticed I typed ,2 on the last date part when that one should be ,4 since you said the year is 4 digits sometimes.
Thanks *so* much so far. There's a error somewhere in the last 2 parsers.
Here's the error:
192.168.10.246:9300 5584 2008-12-08 15:04:53.901 -5 0 0 5284 QOS 1166 1 Audit.RTUsage.QOS <message code="901" location="/qs:command/vali
substring"
QE-DEF-0261 QFWP - Parsing text: If ( [Referral_Auth_Notes] <> null) then
substring( [Referral_Auth_Notes],posi
</message>
By the way, can you recommend any good online resources or books on learning more about Cognos?
Here is PArt 2 with the correct backets I hope. I am just doing this on the fly.
Define Date_Part_2
If ( [Referral_Auth_Notes] <> null) then
(substring([Referral_Auth_
define date part3
If ( [Referral_Auth_Notes] <> null) then
(substring( [Referral_Auth_Notes],posi
This code finds the position of the first '/' and then takes from the slash to the end of the line and searches for another '/'. Once it has found the second '/' it adds the position of the first slash to the position of the second slash and goes back to the original dataline and grabs 4 characters from there and places them in the variable.
Yikes this is fun isn't it.
Business Accounts
Answer for Membership
by: RWrigleyPosted on 2008-11-24 at 14:20:01ID: 23030992
This type of fucntionality is really in the domain of a good ETL tool. The problem you're going to run into is that you obviously can't be sure of what is going to be in the field.
The only thing you can try is a big string function, using a "find" fucntion to find the location of the first "/" in the string, then using substring to grab the two characters immediatly before that. Then find the second slash, and substring the characters between it and the frist slash, then substring the characters after the second slash. Throw those three substrings into a "create_timestamp" function, and voila, you'll have a report that will blow up when you hit a database entry that has random slashes in it, or that puts month before date, or any of a hundred other things that will be next to impossible to plan for in a string manipulation expression.
You're best bet is to use the native database functions for this; that'll ensure that they get pushed to the database. This type of operation is relatviely slow, so you want the database to do it.