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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cdate conversion question

Status
Not open for further replies.

DVFS

Programmer
Sep 21, 2000
44
0
0
US
Hi am am trying to get this string to date conversion working. When I check it it tells me there is no errors in the formula. However when I run the report I get "Bad date format string." Here is what I am trying to use:

if {Contact1.ACCOUNTNO} startswith "A" then
cdate(("200" + {Contact1.ACCOUNTNO} [2 to 6])) else
cdate(("19" + {Contact1.ACCOUNTNO} [1 to 6]))

Any help would be appreciated.

Thanks, Joe
 
I would break this into two steps within one formula, first creating the number to use in the date formula and then applying the date formula:

stringvar predate;
if {Contact1.ACCOUNTNO} startswith "A" then
predate:=("200"+totext({Contact1.ACCOUNTNO},0,"")[2 to 6]) else
predate:=("19"+totext({Contact1.ACCOUNTNO},0,"")[1 to 6]);

datevar todate := date(val(left(predate,4)), val(mid(predate,5,2)), val(mid(predate,7,2)));

This depends on the accountno always having 1-2 digits for the year, 2 for the month, and 2 for the day, possibly followed by other numbers.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top