Skip to main content

Convert Filed to date using a mask inputted by user

Good morning,
I am trying to convert CHAR fields to DATE but I don't want to hadrwire the mask in the equation.
I have tried to wirte concatenate the variable with three and two "" but the result is the same.
Is there a way to let this work in this way? I am almost done with the macro and this is the last bit.
The bit coded is attached, thank you very much for your help.
Vito

Brian Element Wed, 12/02/2020 - 06:19

It is because you are missing a pair of quotes in the msgbox, that is why you are having a blank.

MsgBox ""& DateFormat & "" should be
MsgBox """" & DateFormat & """"

VITOPIEPOLI Wed, 12/02/2020 - 06:25

Hi Brian,
Thank you Brian for your reply, I though it was the same issue but I am afraid it is not working in this case. 
It still give me back Error: A valid mask is required for this field.
I converted it via hardwiring the code, therefore the issue is not with the data.

Brian Element Wed, 12/02/2020 - 10:15

Sorry, I missed that it is a data field you are creating, I thought it was a character.  So your Equation would be:

field.Equation = "@Ctod(""" & DateFormat & """, ""DD-MMM-YYYY"")"

You need to add in the @Ctod to change the character information to date info.

 

VITOPIEPOLI Wed, 12/02/2020 - 10:37

In reply to by Brian Element

Hi Brian,
It was my masteke to post the incorrect code.
Here we are talking about just converting a field from character to date.
As datasets comes with a different formats I wanted the user to declare the date format and the formula do the rest.
I attach the correct code, that is not working.
Regards,
Vito

VITOPIEPOLI Thu, 12/03/2020 - 03:57

In reply to by Brian Element

Thanks for your reply Brian,
unfortunately that equation does not work for a Replace task as in this specific case.
I tried to use with an AppendTask and it works fine as far as the date is not 00/000/0000. It gives me an error when those type of records are parsed.
In my original question I was just wondering if there was a way to mimic the modify field function, is that possible?
Again many thanks for your help and support, very much appreciated.
Kind regards,
Vito