String To Data Conversion

A

ALESSANDRO Baraldi

Good Evening.

Some strange problem:
From MIME decodifie Mail message i get Time_Data_Reference
as String in this STANDARD way:

RIF.: "Sat, 12 Jun 2004 11:59:14 +0100 (CET)"

(Italian reference for the Time +0100)

Now i need to convert this Format in Data to allow to the code
the ORDER_BY (Data), so i CUT the string to allow the conversion:

I try with this:

Private Function retDate(strIn As String) As Date
On Error GoTo errData
Dim myStr As String
myStr = Mid$([Date], 6, Len([Date]) - 17)

'// This is the retturn of my CUT:
'// "12 Jun 2004 11:59:14" CleanString.

retDate = CDate(myStr)
'// Here i get an error and the convesion fail
'// Err n°13 Type not corresponding

Exit Function
errData:
MsgBox Err.Number & " " & Err.Description
End Function


Haveyou some suggestion or idea.....?
 
G

Gerald Stanley

I tried the code in your message but it would not compile. I made the
following change
myStr = Mid$(strIn, 6, Len(strIn) - 17)

and it worked fine with your example.

Hope This Helps
Gerald Stanley MCSD
 
A

ALESSANDRO Baraldi

Gerald Stanley said:
I tried the code in your message but it would not compile. I made the
following change
myStr = Mid$(strIn, 6, Len(strIn) - 17)

and it worked fine with your example.

Hope This Helps
Gerald Stanley MCSD

Hi and thanks.
This is good only for English DataType....!!
My error depend to Italian Conversion..... so
CDate(....) don't know "JUN" because in Italy is "GIU"

Very bad way... i need to sostitute the String with
IT reference.

Bye.
 
D

Dirk Goldgar

ALESSANDRO Baraldi said:
Good Evening.

Some strange problem:
From MIME decodifie Mail message i get Time_Data_Reference
as String in this STANDARD way:

RIF.: "Sat, 12 Jun 2004 11:59:14 +0100 (CET)"

(Italian reference for the Time +0100)

Now i need to convert this Format in Data to allow to the code
the ORDER_BY (Data), so i CUT the string to allow the conversion:

I try with this:

Private Function retDate(strIn As String) As Date
On Error GoTo errData
Dim myStr As String
myStr = Mid$([Date], 6, Len([Date]) - 17)

'// This is the retturn of my CUT:
'// "12 Jun 2004 11:59:14" CleanString.

retDate = CDate(myStr)
'// Here i get an error and the convesion fail
'// Err n°13 Type not corresponding

Exit Function
errData:
MsgBox Err.Number & " " & Err.Description
End Function


Haveyou some suggestion or idea.....?

I'm a little surprised that CDate doesn't recognize English month
abbreviations even when your regional settings are Italian. Not that I
have any documentation that says it should; it's just that MS has often
accepted the English format in addition to the local language. Just out
of curiosity, have you tried the DateValue function?

At worst, you could parse the string into tokens using the Split
function, then translate the second token from the English abbreviation
to the corresponding Italian word, and then reassemble and convert the
date.
 
M

Marshall Barton

ALESSANDRO said:
Some strange problem:
From MIME decodifie Mail message i get Time_Data_Reference
as String in this STANDARD way:

RIF.: "Sat, 12 Jun 2004 11:59:14 +0100 (CET)"

(Italian reference for the Time +0100)

Now i need to convert this Format in Data to allow to the code
the ORDER_BY (Data), so i CUT the string to allow the conversion:

I try with this:

Private Function retDate(strIn As String) As Date
On Error GoTo errData
Dim myStr As String
myStr = Mid$([Date], 6, Len([Date]) - 17)

'// This is the retturn of my CUT:
'// "12 Jun 2004 11:59:14" CleanString.

retDate = CDate(myStr)


You can force US date interpretation by enclosing the date
string in # signs:

Eval("#" & myStr & "#")
 
A

ALESSANDRO Baraldi

Marshall Barton said:
ALESSANDRO said:
Some strange problem:
From MIME decodifie Mail message i get Time_Data_Reference
as String in this STANDARD way:

RIF.: "Sat, 12 Jun 2004 11:59:14 +0100 (CET)"

(Italian reference for the Time +0100)

Now i need to convert this Format in Data to allow to the code
the ORDER_BY (Data), so i CUT the string to allow the conversion:

I try with this:

Private Function retDate(strIn As String) As Date
On Error GoTo errData
Dim myStr As String
myStr = Mid$([Date], 6, Len([Date]) - 17)

'// This is the retturn of my CUT:
'// "12 Jun 2004 11:59:14" CleanString.

retDate = CDate(myStr)


You can force US date interpretation by enclosing the date
string in # signs:

Eval("#" & myStr & "#")

Hi Marsh.
Absolutly OK.

I also try with "#" but withOut Eval function call don't work....!

Tanks a lot.
 
A

ALESSANDRO Baraldi

Dirk Goldgar said:
ALESSANDRO Baraldi said:
Good Evening.

Some strange problem:
From MIME decodifie Mail message i get Time_Data_Reference
as String in this STANDARD way:

RIF.: "Sat, 12 Jun 2004 11:59:14 +0100 (CET)"

(Italian reference for the Time +0100)

Now i need to convert this Format in Data to allow to the code
the ORDER_BY (Data), so i CUT the string to allow the conversion:

I try with this:

Private Function retDate(strIn As String) As Date
On Error GoTo errData
Dim myStr As String
myStr = Mid$([Date], 6, Len([Date]) - 17)

'// This is the retturn of my CUT:
'// "12 Jun 2004 11:59:14" CleanString.

retDate = CDate(myStr)
'// Here i get an error and the convesion fail
'// Err n°13 Type not corresponding

Exit Function
errData:
MsgBox Err.Number & " " & Err.Description
End Function


Haveyou some suggestion or idea.....?

I'm a little surprised that CDate doesn't recognize English month
abbreviations even when your regional settings are Italian. Not that I
have any documentation that says it should; it's just that MS has often
accepted the English format in addition to the local language. Just out
of curiosity, have you tried the DateValue function?

At worst, you could parse the string into tokens using the Split
function, then translate the second token from the English abbreviation
to the corresponding Italian word, and then reassemble and convert the
date.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)

Hi Dirk, thanks for replay.

It's a strange thing but it's really like this.

The Marshall solution is a very PERFECT way.

Work 100%.

Bye
 

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