Link to home
Start Free TrialLog in
Avatar of BostonMA
BostonMAFlag for United States of America

asked on

How to convert a text field to date in crystal reports

I have a field which is of type string and looks like:   20080115 (ie YYYY-mm-dd)

Is there an easier way to convert it to type date than the following formula?


Local StringVar DaypartTemp;
Local StringVar MonthpartTemp;
Local StringVar YearpartTemp;
Local NumberVar Daypart ;
Local NumberVar MonthPart;
Local NumberVar YearPart ;

DayParttemp := Right({V_My_Portfolio_1.Manager Date From}, 2);
MonthParttemp := Mid({V_My_Portfolio_1.Manager Date From}, 5,2);
YearParttemp := Left({V_My_Portfolio_1.Manager Date From}, 4);

Daypart := ToNumber(DaypartTemp);
MonthPart := ToNumber(MonthpartTemp);
YearPart := ToNumber(YearpartTemp);

Date (YearPart,MonthPart,DayPart )



Avatar of UnifiedIS
UnifiedIS

You can just put it all together like this:
DATE(Left({V_My_Portfolio_1.Manager Date From}, 4),
Mid({V_My_Portfolio_1.Manager Date From}, 5,2), Right({V_My_Portfolio_1.Manager Date From}, 2))
ASKER CERTIFIED SOLUTION
Avatar of UnifiedIS
UnifiedIS

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BostonMA

ASKER

Thanks.