Converting a String Variable to a Date Variable

Hi all, just started using the dataport objects of NAV about 3 weeks ago, so fairly new to this.

I have created a dataport that is assigning a value of ‘YYYY-MM-DD’ to a global variable of Text.

What is the best way to convert that String into the proper Date format (DD/MM/YY) or should I just be brave and make the Global Variable a Date rather than Text? I have looked thru the help and can not find any functions that convert Strings into Integers. I thought I would use the CopyStr to get the date values and than use the DMY2Date function to complete this.

I am using NAV 4.0 with a license in which I can not create CodeUnits.

Thanks for any help/push in the right direction.

Stu

Have you tried EVALUATE(DateTypeVariableOrDateTypeField,DateString)?

Thanks! That was the push in the right direced a Global text datatype (gs_UsageDate) and assigned it the manipulated dataport field (gs_UsageDate) than used the EVALUATE function on the Global date datatype (gd_UsageDate)

so dp_s_Date ;= 2009-10-27

gs_UsageDate := COPYSTR(gs_UsageDate, 6, 2) + COPYSTR(gs_UsageDate, 9, 2) + COPYSTR(gs_UsageDate, 3, 2);

EVALUATE(gd_UsageDate, gs_UsageDate);

Worked good. Found out the hard way I ran out of line room by putting the COPYSTR statements into the EVALUATE function.

Am trying to change the way I name variables…

Stu

1 Like

You’re welcome, glad to hear you got that working [Y]

It doesn’t HAVE to be on the same line in the editor you know, you can do this:

EVALUATE(gd_UsageDate,
COPYSTR(gs_UsageDate, 6, 2) +
COPYSTR(gs_UsageDate, 9, 2) +
COPYSTR(gs_UsageDate, 3, 2);

I’ll give the above a try. Still getting use to the C\AL Code windows.

Stu

You also have functions DMY2DATEm DWY2DATE and some others. [Y]