Tip

Converting long values from legacy systems to date fields

Often times legacy systems that we connect to store dates as an 8-digit, integer value in for format yyyymmdd, for example 20020704 would be July 4, 2002. I have tried numerous versions of the Format function, including General Date and m/d/yyyy but always end up with a goofy date, such as 12/31/9999. Here is an approach to convert these 8-digit values into a Notes Date field.

In this example, the field INVDT in olddoc is a number field and contains the 8-digit value read from a legacy system. InvoiceDate in newdoc is a date/time field.


invdt& = Clng(olddoc.INVDT(0)) ' first get the value into a variable of type long, in my example the value is 20020704 tempmo% = invdt& Mod 10000 ' store the least significant 4 digits, in my example the value is 704 tempval& = invdt& - tempmo% ' now remove the least significant 4 digits from initial value, in my example this is 20020000 Yr% = tempval& \ 10000 ' now remove the trailing 0's from tempval, result is 2002 Da% = tempmo% Mod 100 ' now get the least significant 2 digits from tempmo, in my example the value is 4 Mo% = (tempmo% - Da%) \ 100 ' And now remove these least significant digits to get a month, in my example, 7 newdoc.InvoiceDate = Datenumber(Yr%, Mo%, Da%) ' Now I can call Datenumber with 2002, 7, 4 to get a date value.

This was first published in September 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.