Discussion:
Working with date conversions
(too old to reply)
Claus Mygind
2008-12-05 15:03:05 UTC
Permalink
I have an associative array element value "12/5/2008" type is character. I
wish to store it in a variable in dToS() format "20081205".

Should be easy enough (I thought) without using subStr() to pick it appart
and reassemble.

For some reason I keep coming up with a blank value.

Here are some ways I have tried:

~~~~~1st attempt:~~~~~~~~~~~~~~~~~~~~~~
cWorkDay = dToS( cToD( oCGI["WORKDAY"] ))

***Actual result of 1st attempt:***

oCGI["WORKDAY"] = '12/5/2008'
type( 'oCGI["WORKDAY"]' ) = C

cWorkDay =
type( 'cWorkDay') = C
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~2nd attempt:~~~~~~~~~~~~~~~~~~~~~~~~
chk = oCGI["WORKDAY"]
wkDate = cToD(chk)
cWorkDay= dToS( wkDate )

***Actual result of 2nd attempt:***

oCGI["WORKDAY"] = '12/5/2008'
type( 'oCGI["WORKDAY"]' ) = C

chk = '12/5/2008'
type( 'chk' ) = C

wkDate = / /
type( 'wkDate' ) = D
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Roland Wingerter
2008-12-05 16:03:54 UTC
Permalink
Post by Claus Mygind
I have an associative array element value "12/5/2008" type is character. I
wish to store it in a variable in dToS() format "20081205".
Should be easy enough (I thought) without using subStr() to pick it appart
and reassemble.
For some reason I keep coming up with a blank value.
~~~~~1st attempt:~~~~~~~~~~~~~~~~~~~~~~
cWorkDay = dToS( cToD( oCGI["WORKDAY"] ))
***Actual result of 1st attempt:***
oCGI["WORKDAY"] = '12/5/2008'
type( 'oCGI["WORKDAY"]' ) = C
---------
Try the class dateExEx.cc posted in this message: dbase.shared-code, subject
"Converting string to date or Datetime", 27. February 2008.

set proc to dateExEx.cc additive
cDate = '12/5/2008'
? dtos(new dateexex().stringToDate(cDate)) // 20080512

Roland
Claus Mygind
2008-12-05 16:45:40 UTC
Permalink
Thanks Roland,

As usual these are things are of one's own making. It turned out I was
storing an extra set of delimiters around the value both single and double
quotes " '.

Once I checked the length of the string and what the extra values were in
the first and last postion, I saw the problem.

So my original attempt was adequate for my needs

var = dtos( ctod( a['charDate'] ))
Roland Wingerter
2008-12-06 07:36:28 UTC
Permalink
Post by Claus Mygind
Thanks Roland,
As usual these are things are of one's own making. It turned out I was
storing an extra set of delimiters around the value both single and
double quotes " '.
--------
Glad you solved it!

Roland

Loading...