Date Conversion

G

Greg Maxey

Is there any way to preserve formatting with date conversion.

Sub Test()
Dim myString As String
Dim myDate As Date
myString = "February 12, 1969"
myDate = CDate(myString)
End Sub

myDate in the above is returned as 2/12/69. I am trying to figure out how
to preserve the date format during conversion. If myString is 2/12/69 then
myDate should be 2/12/69. If myString is 12 February 1969 then myDate
should be 12 February 1969.

Can this be done without some elaborate analysis of mySting and setting up a
Format(myDate, ......) statement?

Thanks.
 
D

Doug Robbins

Hi Greg,

By definition, CDate returns a Date data type which is defined as:

"A data type used to store dates and times as a real number. Date variables
are stored as 64-bit (8-byte) numbers. The value to the left of the decimal
represents a date, and the value to the right of the decimal represents a
time."

This would make the answer to your specific question as "No"

You can of course "re-create" the format using the Format() function. So I
guess your real question is how can you determine the format of a string
that contains a date so that you can re-create that format.?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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

Similar Threads


Top