A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Convert text to Date



 
 
Thread Tools Display Modes
  #1  
Old May 13th, 2008, 03:32 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Jasper Recto
external usenet poster
 
Posts: 257
Default Convert text to Date

We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I convert it
to a regular date field before it goes into my database?

Thanks,
Jasper


  #2  
Old May 13th, 2008, 03:49 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Michel Walsh
external usenet poster
 
Posts: 2,404
Default Convert text to Date

If the starting value is numerical:

DateSerial( value \ 10000, (value MOD 10000)\100, value MOD 100 )


If the starting value is a string (always 8 characters):

DateSerial( Left(value, 4), Mid(value, 5, 2), Right(value, 2) )




Hoping it may help,
Vanderghast, Access MVP



"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I convert
it to a regular date field before it goes into my database?

Thanks,
Jasper



  #3  
Old May 13th, 2008, 03:54 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
fredg
external usenet poster
 
Posts: 4,386
Default Convert text to Date

On Tue, 13 May 2008 10:32:44 -0400, Jasper Recto wrote:

We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I convert it
to a regular date field before it goes into my database?

Thanks,
Jasper


To convert an 8 character string to a Date datatype value you can use
the DateSerial function. Look it up in VBA help.

I would import the data as a string.
After it's in your database, add a new field DateTime datatype to the
table, then run an update query:

Update YourTable Set YourTable.NewDateField =
DateSerial(Left([OldFieldName],4),Mid([OldFieldName],5,2),Right([OldFieldName],2))

Then delete to old field from the table (or not).


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
  #4  
Old May 13th, 2008, 04:04 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Convert text to Date

Yes. When you're importing, click on the Advanced button in the bottom
left-hand corner of the wizard. Set the field's Data Type to Date/Time, set
the Date Order to YMD, set the Date Delimiter to nothing and check the Four
Digit Year checkbox.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I convert
it to a regular date field before it goes into my database?

Thanks,
Jasper



  #5  
Old May 13th, 2008, 04:55 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Convert text to Date

Since the incoming value is yyyymmdd, there's an even easier way that will
work for numeric or text:

CDate(Format(value, "0000\-00\-00"))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
If the starting value is numerical:

DateSerial( value \ 10000, (value MOD 10000)\100, value MOD 100 )


If the starting value is a string (always 8 characters):

DateSerial( Left(value, 4), Mid(value, 5, 2), Right(value, 2) )




Hoping it may help,
Vanderghast, Access MVP



"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I convert
it to a regular date field before it goes into my database?

Thanks,
Jasper





  #6  
Old May 14th, 2008, 02:55 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Michel Walsh
external usenet poster
 
Posts: 2,404
Default Convert text to Date

Indeed. :-)


Vanderghast, Access MVP


"Douglas J. Steele" wrote in message
...
Since the incoming value is yyyymmdd, there's an even easier way that will
work for numeric or text:

CDate(Format(value, "0000\-00\-00"))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
If the starting value is numerical:

DateSerial( value \ 10000, (value MOD 10000)\100, value MOD 100 )


If the starting value is a string (always 8 characters):

DateSerial( Left(value, 4), Mid(value, 5, 2), Right(value, 2) )




Hoping it may help,
Vanderghast, Access MVP



"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I
convert it to a regular date field before it goes into my database?

Thanks,
Jasper







  #7  
Old May 14th, 2008, 05:33 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Jasper Recto
external usenet poster
 
Posts: 257
Default Convert text to Date

Douglas,

The CDate works great in a query.

Do you know if it's possible to convert data from a TransferText using this
format?

I have a command button that prompts for a file. It than imports a file
into an existing database using an import specifications.

Is there a way to convert that text into the date format BEFORE it goes into
the database table?

Thanks!

Jasper
"Douglas J. Steele" wrote in message
...
Since the incoming value is yyyymmdd, there's an even easier way that will
work for numeric or text:

CDate(Format(value, "0000\-00\-00"))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
If the starting value is numerical:

DateSerial( value \ 10000, (value MOD 10000)\100, value MOD 100 )


If the starting value is a string (always 8 characters):

DateSerial( Left(value, 4), Mid(value, 5, 2), Right(value, 2) )




Hoping it may help,
Vanderghast, Access MVP



"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I
convert it to a regular date field before it goes into my database?

Thanks,
Jasper







  #8  
Old May 14th, 2008, 06:07 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Douglas J. Steele
external usenet poster
 
Posts: 9,313
Default Convert text to Date

You need to create an Import Specification (which you can do using the
approach I mentioned in my other post in this thread), and then use that
Import Specification with the TransferText method.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jasper Recto" wrote in message
...
Douglas,

The CDate works great in a query.

Do you know if it's possible to convert data from a TransferText using
this format?

I have a command button that prompts for a file. It than imports a file
into an existing database using an import specifications.

Is there a way to convert that text into the date format BEFORE it goes
into the database table?

Thanks!

Jasper
"Douglas J. Steele" wrote in message
...
Since the incoming value is yyyymmdd, there's an even easier way that
will work for numeric or text:

CDate(Format(value, "0000\-00\-00"))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
If the starting value is numerical:

DateSerial( value \ 10000, (value MOD 10000)\100, value MOD 100 )


If the starting value is a string (always 8 characters):

DateSerial( Left(value, 4), Mid(value, 5, 2), Right(value, 2) )




Hoping it may help,
Vanderghast, Access MVP



"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I
convert it to a regular date field before it goes into my database?

Thanks,
Jasper









  #9  
Old May 14th, 2008, 08:42 PM posted to microsoft.public.access,microsoft.public.access.forms,microsoft.public.access.queries
Jasper Recto
external usenet poster
 
Posts: 257
Default Convert text to Date

Awesome!!!

Thanks,
Jasper
"Douglas J. Steele" wrote in message
...
You need to create an Import Specification (which you can do using the
approach I mentioned in my other post in this thread), and then use that
Import Specification with the TransferText method.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jasper Recto" wrote in message
...
Douglas,

The CDate works great in a query.

Do you know if it's possible to convert data from a TransferText using
this format?

I have a command button that prompts for a file. It than imports a file
into an existing database using an import specifications.

Is there a way to convert that text into the date format BEFORE it goes
into the database table?

Thanks!

Jasper
"Douglas J. Steele" wrote in message
...
Since the incoming value is yyyymmdd, there's an even easier way that
will work for numeric or text:

CDate(Format(value, "0000\-00\-00"))

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Michel Walsh" vanderghast@VirusAreFunnierThanSpam wrote in message
...
If the starting value is numerical:

DateSerial( value \ 10000, (value MOD 10000)\100, value MOD 100 )


If the starting value is a string (always 8 characters):

DateSerial( Left(value, 4), Mid(value, 5, 2), Right(value, 2) )




Hoping it may help,
Vanderghast, Access MVP



"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I
convert it to a regular date field before it goes into my database?

Thanks,
Jasper











  #10  
Old May 21st, 2008, 09:34 AM posted to microsoft.public.access.forms,microsoft.public.access.queries,microsoft.public.access
catharinus van der werf
external usenet poster
 
Posts: 6
Default Convert text to Date

Hello to you all,

I tried the statement in my query to insert a text file in an accces
database, but it failed. Don't know why. Please help:
The statement:

Call conConnection.Execute("INSERT INTO [TABELB] (DATUM) SELECT
CDATE(DATUM,0000\-00\-00) AS DATUM FROM [text;HDR=NO;DATABASE=" & App.Path &
"\telebank\gtz].[table4.asc]")


catharinus van der werf



"Douglas J. Steele" wrote:

Yes. When you're importing, click on the Advanced button in the bottom
left-hand corner of the wizard. Set the field's Data Type to Date/Time, set
the Date Order to YMD, set the Date Delimiter to nothing and check the Four
Digit Year checkbox.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Jasper Recto" wrote in message
...
We have dates that are in this format:

20080513

This is the date for 5/13/2008

If I import data from a text file that has this format, how can I convert
it to a regular date field before it goes into my database?

Thanks,
Jasper




 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:40 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.