Is there any way where I can convert a character field to a date field programatically. I am trying to match some records based on if they are >= date1(yymmdd) and <= date2(yymmdd). This won't work for 1999 and earlier.(99 > 01)
ASM,
You mention your character field is 10 characters long. Your original message assumes date is in the YYMMDD format. What does you 10 byte field look like? If it is in the form:
2001/01/10, SUBSTR would yield: "2001/0"
Which will yield " / / "
What you need is a better string manipualtion. Assuming you want to pass an 8 character string to CTOD. There are numerous ways to try this, but note that the CTOD function expects the YEAR to be your last digits, unless you have set your global DATE functionality to something other than the MM/DD/YYYY format. For best accuracy, I would reccomend this (where lcMYDATE is the name of your date field):
My example from above will yield: "01/10/2001", which can then be safely passed to CTOD. CTOD will accept either "01/10/2001" or "01/10/01" as valid date formats.
HI
SET CENTURY ON
SET DATE YMD
LOCATE FOR BETWEEN(CTOD(myCharacterDateField)),date1,date2)
** where date1 and date2 are date format dates
Hope this helps you ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
The other "/" character was not being placed by any of the string extractions. The first one is coverd in the SUBSTR, the other two were not. Also, I think I was a little vague in my explaination as to WHY you were getting " / / ", upon re-reading it. To be more specific, the SUBSTR line that you are issuing:
ctod(substr(field1,1,6))
Is returning a blank date, because your date value looks like one of two things:
1) "2001/01/01" which will return "2000/0", and when placed through the CTOD function will return " / / "
or
2) "01/01/01" which when run through your code will return "01/01/" which will also when placed through the CTOD function will return " / / ".
So, as mentioned before, you need better manipulation of your date strings before putting them through the CTOD routine. That should solve your troubles...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.