Convert Filed to date using a mask inputted by user

7 posts / 0 new
Last post
VITOPIEPOLI
Offline
Joined: 10/29/2019 - 11:28
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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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
Offline
Joined: 10/29/2019 - 11:28

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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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
Offline
Joined: 10/29/2019 - 11:28

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

Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

Ok, I think this might be the one you are looking for.

field.Equation = "@Ctod(DATE_FIELD, """ & DateFormat & """)"

VITOPIEPOLI
Offline
Joined: 10/29/2019 - 11:28

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