Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CDATE error

Status
Not open for further replies.

DerickB

Technical User
Jan 17, 2002
3
US
When I use this syntax: CDate ({HISTAS.TDATE})
to convert a string to a date I get the error: bad date format srting. The field in the database is a string set like this-yyyymmdd. Any help would be appreciated.
 
Is it a string or an 8 digit integer? Several programs, Macola and ACCPAC being the ones I am most familiar with, store their dates as 8 digit integers.

If this is the case go to the CD website and download the NumbertoDate UFL.

If that is not the case, you need to parse out the string as follows:

Date(ToNumber(Left({String},4)),ToNumber(mid({string},5,2)),ToNumber(Right({string},2))) Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
I will try parsing the string, but why would CDATE not work.
 
How would you use that string parse formula for an 8 digit integer for same result? Thanks for your post. ss26
 
Numbertodate({numberfield}) will do the trick if {numberfield} is an 8 digit integer in the YYYYMMDD format. Software Support for Macola, Crystal Reports and Goldmine
dgilsdorf@mchsi.com
 
I found this at Ken's FAQ location. Thanks for both.

WhilePrintingRecords;
NumberVar input := {A.ISDATE}; // or whatever your field name is
// This line checks for a minimum value, any value will work.
If input < 19590101 then Date (1959, 01, 01) else

Date ( Val (ToText (input, 0 , &quot;&quot;) [1 to 4]),
Val (ToText (input, 0 , &quot;&quot;) [5 to 6]),
Val (ToText (input, 0 , &quot;&quot;) [7 to 8]) )

ss26
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top