Converting the Data Type from Text to Date

Hi All, I got a text variable which is having a date, now I want to convert that text to a date. Please Help me with a example.

  • Regards, Raveendran

Simplest solution is to use command EVALUATE(MyDate,MyString).

But it could cause problems - evaluation is processed depending on regional settings.

You can use function for doing that. It is converting string with date in format YYYYMMDD. If you need another format, you can change it.

EvaluateDate(VAR ResultDate : Date;SourceText : Text[8]) : Boolean
IF NOT EVALUATE(Year,COPYSTR(SourceText,1,4)) THEN
EXIT(FALSE);

IF Year < 0 THEN
EXIT(FALSE);

IF NOT EVALUATE(Month,COPYSTR(SourceText,5,2)) THEN
EXIT(FALSE);

IF (Month < 1) OR (Month > 12) THEN
EXIT(FALSE);

IF NOT EVALUATE(Day,COPYSTR(SourceText,7,2)) THEN
EXIT(FALSE);

IF (Day < 1) OR (Day > DATE2DMY(CALCDATE(’<+CM>’,DMY2DATE(1,Month,Year)),1)) THEN
EXIT(FALSE);

ResultDate := DMY2DATE(Day,Month,Year);

EXIT(TRUE);

Three integer variables Year, Month, Day are defined in local variables of the function.

[8] means [ 8 ] [:)]

So a generic way of looking at it… first you have to make sure that the text variable is formatted as a valid date string, and then you use the EVALUATE command to convert it to a Date variable. Viktoras was kind enough to spend some time to give you one way to do that, and there are many other ways to do the same thing.

Hi I got it Thank You.