Date conversions

L

.Len B

I have to import data from an ASCII text file and
use INSERT INTO ... to create records in an existing
table.

There are a couple of fields with dates in the form
Mar 05,10

I know that I can set the 9 characters into a string and
manipulate the string using format(... to massage the data
into a form suitable for the SQL string using #s.

I was just wondering if that technique is the most efficient
or is there a better approach?
 
J

John W. Vinson

I have to import data from an ASCII text file and
use INSERT INTO ... to create records in an existing
table.

There are a couple of fields with dates in the form
Mar 05,10

I know that I can set the 9 characters into a string and
manipulate the string using format(... to massage the data
into a form suitable for the SQL string using #s.

I was just wondering if that technique is the most efficient
or is there a better approach?

Only a little massage is needed:

?cdate("Mar 05,10")
3/5/2010
 
L

.Len B

Thanks John
That sure beats slicing and reassembling the string myself
which was what I had in mind.

I just knew there would be something better.

--
Len
______________________________________________________
remove nothing for valid email address.
| On Wed, 10 Mar 2010 11:18:19 +1000, ".Len B"
<[email protected]>
| wrote:
|
| >I have to import data from an ASCII text file and
| >use INSERT INTO ... to create records in an existing
| >table.
| >
| >There are a couple of fields with dates in the form
| >Mar 05,10
| >
| >I know that I can set the 9 characters into a string and
| >manipulate the string using format(... to massage the data
| >into a form suitable for the SQL string using #s.
| >
| >I was just wondering if that technique is the most efficient
| >or is there a better approach?
|
| Only a little massage is needed:
|
| ?cdate("Mar 05,10")
| 3/5/2010
|
|
| --
|
| John W. Vinson [MVP]
|
 
T

Tom van Stiphout

On Wed, 10 Mar 2010 11:18:19 +1000, ".Len B"

That actually is a valid date, so no conversion would be needed. Type
this in the Immediate window:
?IsDate("Mar 05,10")
True

-Tom.
Microsoft Access MVP
 
L

.Len B

Thanks Tom,
John's suggestion didn't work as presented. I had to surround the
result with # characters to make it acceptable in the VALUES clause
of the INSERT INTO".

I expect yours will behave similarly. Both generate a True in IsDate.

I dare say that if I were to change my regional settings then I
wouldn't need any #.
--
Len
______________________________________________________
remove nothing for valid email address.
| On Wed, 10 Mar 2010 11:18:19 +1000, ".Len B"
|
| That actually is a valid date, so no conversion would be needed. Type
| this in the Immediate window:
| ?IsDate("Mar 05,10")
| True
|
| -Tom.
| Microsoft Access MVP
|
|
| >I have to import data from an ASCII text file and
| >use INSERT INTO ... to create records in an existing
| >table.
| >
| >There are a couple of fields with dates in the form
| >Mar 05,10
| >
| >I know that I can set the 9 characters into a string and
| >manipulate the string using format(... to massage the data
| >into a form suitable for the SQL string using #s.
| >
| >I was just wondering if that technique is the most efficient
| >or is there a better approach?
 
J

John W. Vinson

I dare say that if I were to change my regional settings then I
wouldn't need any #.

Nope. An INSERT INTO a date/time field needs # delimiters. The format is
irrelevant.
 
D

De Jager

.Len B said:
I have to import data from an ASCII text file and
use INSERT INTO ... to create records in an existing
table.

There are a couple of fields with dates in the form
Mar 05,10

I know that I can set the 9 characters into a string and
manipulate the string using format(... to massage the data
into a form suitable for the SQL string using #s.

I was just wondering if that technique is the most efficient
or is there a better approach?
 

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