formatting imported fields-help

J

janet

Hello,
I am trying to convert an imported field from my database but my code is not
working . . .please help. The field date imports as follow 100104 (for 2010)
and 91231 (for 2009). . . being 9 the year, 12 the month, and 31 the day for
2009 and respectively for 2010. . . and i need to convert it as follow. . .
mm/dd/yyyy. . . how can i process this ? ?Please advise.Thanks.
 
A

Allen Browne

janet said:
Hello,
I am trying to convert an imported field from my database but my code is
not working . . .please help. The field date imports as follow 100104 (for
2010) and 91231 (for 2009). . . being 9 the year, 12 the month, and 31 the
day for 2009 and respectively for 2010. . . and i need to convert it as
follow. . . mm/dd/yyyy. . . how can i process this ? ?Please
advise.Thanks.

If your imported field is named [d], either expression below should work.

If it's a Number field, use:
DateSerial([d] \ 10000, ([d] \ 100) Mod 100, [d] Mod 100)

If it's a Text field, use:
DateSerial(Left(Format([d], "000000"),2), Mid(Format([d], "000000"),2),
Right([d],2))

Either way, you probably need to test for Null to avoid errors:
IIf([d] Is Null, Null, DateSerial([d] \ 10000, ([d] \ 100) Mod 100, [d] Mod
1000))
 
T

Tom van Stiphout

On Tue, 19 Jan 2010 11:44:09 +0800, "Allen Browne"

You probably meant:
Mid(Format([d], "000000"),3,2)

-Tom.
Microsoft Access MVP

janet said:
Hello,
I am trying to convert an imported field from my database but my code is
not working . . .please help. The field date imports as follow 100104 (for
2010) and 91231 (for 2009). . . being 9 the year, 12 the month, and 31 the
day for 2009 and respectively for 2010. . . and i need to convert it as
follow. . . mm/dd/yyyy. . . how can i process this ? ?Please
advise.Thanks.

If your imported field is named [d], either expression below should work.

If it's a Number field, use:
DateSerial([d] \ 10000, ([d] \ 100) Mod 100, [d] Mod 100)

If it's a Text field, use:
DateSerial(Left(Format([d], "000000"),2), Mid(Format([d], "000000"),2),
Right([d],2))

Either way, you probably need to test for Null to avoid errors:
IIf([d] Is Null, Null, DateSerial([d] \ 10000, ([d] \ 100) Mod 100, [d] Mod
1000))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top