Issue with Date Conversion

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
sahityab
Participant
Posts: 14
Joined: Fri Jun 24, 2011 7:51 am

Issue with Date Conversion

Post by sahityab »

Hi,
I am having an issue with conversion of string to date....
the incomming date can come in the following format
9/24/2008 or 9/9/2008 or 12/1/2008 or 12/12/2008
If i use the follwoing format
StringToDate(lnk_SRC_TRANSLATION_STAGE.EXP_DATE,"%mm/%dd/%yyyy")
I am getting the error as
Data string '9/24/2008' does not match format '%mm/%dd/%yyyy': the value for tag %mm has fewer characters than expected.

Please help...
Thanks
Sahitya
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

As documented within the Parallel Job Developer's Guide and discussed many times within this forum, use %d and %m to handle variable-width day and month fields.

A simple search for "date formats" within the product documentation will lead you to a table of available date and time formats.

Regards,
- james wiles


All generalizations are false, including this one - Mark Twain.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I don't have my documentation with me and search isn't turning up what I'm looking for - there's a date format modifier that allows a portion (month, day, etc) to be 1 or 2 characters... 's' is coming to mind but it is spelled out in the docs.

James, I don't think the single letter formats handle both, pretty sure it handles just one and the magical "s" thingie I'm seeing in my head allows it to handle either size. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sahityab
Participant
Posts: 14
Joined: Fri Jun 24, 2011 7:51 am

Post by sahityab »

Hi
Thank you for your responses i should have checked the documentation first....it was easy enough...i am posting the answer for those like me looking for the answer

Specify this option to allow leading spaces in date formats. The s option is specified in the form:
%(tag,s)
Where tag is the format string. For example:
%(m,s)
indicates a numeric month of year field in which values can contain leading spaces or zeroes and be one or two characters wide. If you specified the following date format property:
%(d,s)/%(m,s)/%yyyy
Then the following dates would all be valid:
8/ 8/1958
08/08/1958
8/8/1958


i used the format %m%d%yyyy for my case and it works
Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Hmmm... then I wonder why have the ',s' modifier if '%m' or '%d' does the trick? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
sahityab
Participant
Posts: 14
Joined: Fri Jun 24, 2011 7:51 am

Post by sahityab »

i had the same question too..
MarkB
Premium Member
Premium Member
Posts: 95
Joined: Fri Oct 27, 2006 9:13 am

Post by MarkB »

chulett wrote:Hmmm... then I wonder why have the ',s' modifier if '%m' or '%d' does the trick? :?
The 's' option will accept dates that have leading spaces in the date, like '10/ 8/2011 ... %d or %m by itself will choke if there is an embedded space.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I was wondering if that was the only difference... not sure how useful that turns out to be as I don't recall ever seeing a date with internal spaces like that. [shrug]

Ah well, at least now we know.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

%d matches a single digit in the date. %dd matches two digits in the date. %dd,v allows the format to be variable (one digit or two). There are other variations.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
max.madsen
Premium Member
Premium Member
Posts: 62
Joined: Tue Dec 07, 2004 7:41 am
Location: Brasil
Contact:

Re: Issue with Date Conversion

Post by max.madsen »

One way to solve:
Use the Field to separate the day, month and year.
Field (column,'/', 1) for the month
Field (column,'/', 2) for the day
Field (column,'/', 3) for the year
After that, use the Str function to complete on the left of zero day and month, if necessary.
Then finally, concatenate the results.

May not be the best way, but it solves. :lol:
jwiles
Premium Member
Premium Member
Posts: 1274
Joined: Sun Nov 14, 2004 8:50 pm
Contact:

Post by jwiles »

The v option is for use with day of year %ddd. %d and %m handle variable-width day and month respectively. The s option adds support for leading spaces (old-school for lining up rows on 132-column reports, etc.)
- james wiles


All generalizations are false, including this one - Mark Twain.
Post Reply