cancel
Showing results for 
Search instead for 
Did you mean: 

Converting String date to Crystal Date format

Former Member
0 Kudos
94

Post Author: bsimpsonky

CA Forum: Formula

I have a SQL database that stores dates in mmddyyy string format. I need to convert this string format into a crystal date format so that it can be properly evaluated with crystal date range parameters.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Post Author: bsimpsonky

CA Forum: Formula

This took care of my problem. Thanks!!!!!!

Former Member
0 Kudos

Post Author: bettername

CA Forum: Formula

Does it have slashes in? Not that it matters, this'll take them out...

//remove the slashes (if they exists) from the date string and assign to a variable since I can't be bother to type out the field name each timestringvar mydate:=replace(,"/","");

//get the individual dateparts from the string and assign to number variable (lookup the date() function to see why)numbervar the_day:=tonumber(mid(mydate, 3,2)); //day = the middle 3rd and 4th characters from the stringnumbervar the_month:=tonumber(left(mydate,2)); //month = 1st and 2nd characters from the stringnumbervar the_year:=tonumber(right(mydate, 4));//year = last 4 characters from the string

//convert the dateparts to a date date(the_year,the_month,the_day);

Former Member
0 Kudos

Post Author: bsimpsonky

CA Forum: Formula

Thanks for the speedy reply. I'm sure this will work, but I was in error about the string format. It is actually stored as mm/dd/yyy, so how would that date conversion be accomplished?

Former Member
0 Kudos

Post Author: bettername

CA Forum: Formula

stringvar mydate:=;

//get the inidivual dateparts from the string

numbervar the_day:=tonumber(left(mydate,2));numbervar the_month:=tonumber(mid(mydate, 3,2));numbervar the_year:=tonumber(right(mydate, 4));

//convert the dateparts to a date

date(the_year,the_month,the_day);