PC Review


Reply
Thread Tools Rate Thread

Converting Text to short date

 
 
=?Utf-8?B?c3RlZmJ1cmdhcw==?=
Guest
Posts: n/a
 
      5th Mar 2006
I currently have an imported file from an other database system, the date
structure is coming across in text format as 12th December 2004 etc however I
need to convert this data to short date format but when I do this as part of
the table the system wips my data and I have to import again. Does anyone
have any suggestions on how I can fix.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      5th Mar 2006
Based on the quick testing I just did, it's the ordinal information (st, th,
etc) that's causing the problem.

Import the data to a temporary table. Write a function that removes the
ordinal information from the text, then uses CDate() to convert it. Use that
function in a query to convert the date and append to the proper table.

Assuming you're using Access 2000 or newer, the function would look
something like the following untested aircode:

Function ConvertTextDate(TextDate As String) As Date

Dim strDate As String

strDate = Replace(TextDate, "st", "")
strDate = Replace(strDate, "nd", "")
strDate = Replace(strDate, "rd", "")
strDate = Replace(strDate, "th", "")
ConvertTextDate = CDate(strDate)

End Function

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


"stefburgas" <(E-Mail Removed)> wrote in message
news:CECFE670-2732-494F-9F6C-(E-Mail Removed)...
>I currently have an imported file from an other database system, the date
> structure is coming across in text format as 12th December 2004 etc
> however I
> need to convert this data to short date format but when I do this as part
> of
> the table the system wips my data and I have to import again. Does anyone
> have any suggestions on how I can fix.



 
Reply With Quote
 
tina
Guest
Posts: n/a
 
      5th Mar 2006
the format (Short Date, Long Date, etc) is immaterial - you can set that any
way you want. the issue is converting a text string to a Date/Time *value*,
which is a numeric value. if the date string is *always* in the format you
posted, you can import the date field as Text, then update the table after
the import, with an Update query, using the following steps:

add an extra field to the table, with Date/Time data type; i'll call it
RealDate. paste the following function into a standard module in your
database. if you create a new module to put it in, do *not* name the module
the same as the function.

Public Function isDate(ByVal strDate As String)

Dim str() As String
str() = Split(strDate)

isDate = CDate(str(1) & " " _
& IIf(Len(str(0)) = 3, Left(str(0), 1), Left(str(0), 2)) _
& " " & str(2))

End Function

run an Update query to update the RealDate field in the table with the
converted date value, as

UPDATE TableName SET TableName.RealDate =
IsDate([TableName].[DateTextField]);

substitute the correct names of the table, the "real date" field, and the
"date as text" field, of course.

hth


"stefburgas" <(E-Mail Removed)> wrote in message
news:CECFE670-2732-494F-9F6C-(E-Mail Removed)...
> I currently have an imported file from an other database system, the date
> structure is coming across in text format as 12th December 2004 etc

however I
> need to convert this data to short date format but when I do this as part

of
> the table the system wips my data and I have to import again. Does anyone
> have any suggestions on how I can fix.



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Short date to a string TimH Microsoft Access Getting Started 2 25th Mar 2008 07:57 PM
Converting numeric value into short date BBAL20 Microsoft Access Queries 2 19th Mar 2008 07:12 PM
Converting a Julian style date to "short date" format =?Utf-8?B?S2V2aW4gTmV3bWFu?= Microsoft Access 4 30th Apr 2007 08:08 PM
converting general date format data into short date format savigliano Microsoft Access Form Coding 3 27th Nov 2006 04:37 AM
converting short to unicode without System.Text.UnicodeEncoding =?Utf-8?B?aXdkdTE1?= Microsoft VB .NET 4 13th Jul 2006 12:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:43 AM.