Page 1 of 1

Issue with Date Conversion

Posted: Thu Oct 13, 2011 8:25 am
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

Posted: Thu Oct 13, 2011 8:33 am
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,

Posted: Thu Oct 13, 2011 8:37 am
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. :?

Posted: Thu Oct 13, 2011 8:58 am
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

Posted: Thu Oct 13, 2011 9:16 am
by chulett
Hmmm... then I wonder why have the ',s' modifier if '%m' or '%d' does the trick? :?

Posted: Thu Oct 13, 2011 9:50 am
by sahityab
i had the same question too..

Posted: Thu Oct 13, 2011 10:11 am
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.

Posted: Thu Oct 13, 2011 11:21 am
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.

Posted: Thu Oct 13, 2011 1:09 pm
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.

Re: Issue with Date Conversion

Posted: Thu Oct 13, 2011 4:59 pm
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:

Posted: Thu Oct 13, 2011 8:04 pm
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.)