Changing a character date field to a date field

Primary tabs

6 posts / 0 new
Last post
Brian Element's picture
Brian Element
Joined: 07/11/2012 - 19:57
Changing a character date field to a date field

Date fields can come in many different varieties.  Visual Basic has a function called CDate that is able to figure out the majority of the formats and translate them into a common format.  The following is the code for a custom function to do the change.

Option Explicit
Function CtoDate(p1 As String) As Date
    ctodate = CDate(p1)
End Function

Joined: 10/25/2014 - 11:26

I think this doesn't work if you're importing using SQL server and the dates come as Numeric in a format that IDEA can't understand. You'll use these and other formulae but you'll end up with "Error" for each record of the field. Currently my problem, but I've had to export my databases to Access where I can fix that.

Joined: 08/22/2018 - 16:11

I need to change a character field that has both MM/DD/YYYY and MM/D/YYYY to a date field.  the @ctod function doesn't work for the 10/1/2018.  Any help would be appreciated.

Steven Luciani
Joined: 07/31/2012 - 13:20


The attached text file contains the equation you need. Open the text file and copy and paste the contents into the equation editor of IDEA.  It uses @ctod, but also uses @getat and @insert to insert leading zeroes for months and days that are missing them.

You will need to use the equation editor's find/replace button. 5th from the left on the equation editor toolbar to replace my generic field name with your date's field name.

The return for this equation is mm/dd/yyyy. This can be tweaked to dd/mm/yyyy if you happen to come across that format as well. Simply change the date mask inside the quotation marks at the end of the equation.

Also, if your separator in the field is something other than /, say a hyphen -, you can also use find and replace to edit the separator.



Joined: 08/22/2018 - 16:11

Thank you very much.  It worked! 

Universidad San...
Joined: 12/22/2020 - 15:37

Thank you very much, for your help!