Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default CSV File - Date Formats

Hi All
I have a CSV file that contains dates held in European format (dd/mm/yyyy).
When I open it manually using Excel, the dates remain unchanged. If I open
it using VBA then the dates are changed to US format where they can... so
01/04/2005 becomes 04/01/2005. However dates that cannot be converted eg
23/03/2005 are left as is. I end up with a mixture of dates and formatting
does reset my dates to the correct format!

How can I avoid this problem?

--
Cheers
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default CSV File - Date Formats


CSV files have a specification.....! (Yup...)

One of the things it states is that dates should be in the format
YYYYMMDD. It's then up to the receiving application to reformat these
as appropriate.

If you can, get the output changed to conform to the specification,
otherwise rather than input them into a date variable, enter them into
a string and then convert that to a date which will give you control
over the format of the date.


--
Rich_z
------------------------------------------------------------------------
Rich_z's Profile: http://www.excelforum.com/member.php...o&userid=24737
View this thread: http://www.excelforum.com/showthread...hreadid=394524

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default CSV File - Date Formats

Nigel,

Without seeing your code it is difficult to comment but you could adapt the
following for your code so that each extracted date is re-formatted as in
the second line of this code.


MyVar = "12/13/05"
Range("A1").Value = Format(MyVar, "dd/mm/yy")

HTH

Andi


"Nigel" wrote in message
...
Hi All
I have a CSV file that contains dates held in European format

(dd/mm/yyyy).
When I open it manually using Excel, the dates remain unchanged. If I

open
it using VBA then the dates are changed to US format where they can... so
01/04/2005 becomes 04/01/2005. However dates that cannot be converted eg
23/03/2005 are left as is. I end up with a mixture of dates and

formatting
does reset my dates to the correct format!

How can I avoid this problem?

--
Cheers
Nigel






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default CSV File - Date Formats

I have US English, so I don't personally have to deal with this problem, but
here is my understanding:


In Excel 2002/2003, there are some options you can use to control this.

expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password,
WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable,
Notify, Converter, AddToMru, Local, CorruptLoad)

help on Local:
Local Optional Variant. True saves files against the language of Microsoft
Excel (including control panel settings). False (default) saves files
against the language of Visual Basic for Applications (VBA) (which is
typically US English)


In other versions, you can rename the file as .txt, then open it using the
text import wizard. In the wizards last screen, you can specify for that
column of dates, how they should be interpreted.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi All
I have a CSV file that contains dates held in European format

(dd/mm/yyyy).
When I open it manually using Excel, the dates remain unchanged. If I

open
it using VBA then the dates are changed to US format where they can... so
01/04/2005 becomes 04/01/2005. However dates that cannot be converted eg
23/03/2005 are left as is. I end up with a mixture of dates and

formatting
does reset my dates to the correct format!

How can I avoid this problem?

--
Cheers
Nigel






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default CSV File - Date Formats

Hi Nigel,

You've already received some answers on this but to give you a specific
example (copied from an answer I posted to someone else a few weeks ago):

<<You can get round this easily by specifying, when opening, how you
want each column to be interpreted. In the below example I've said
columns 1 and 2 should be considered as DMY and column 3 should be MDY.

Sub openfiledates()

Dim myFieldInfo As Variant

myFieldInfo = Array(Array(1, xlDMYFormat), _
Array(2, xlDMYFormat), _
Array(3, xlMDYFormat))

Workbooks.OpenText Filename:="c:\temp\temp.txt", _
DataType:=xlDelimited, _
Comma:=True, _
FieldInfo:=myFieldInfo

End Sub





Nigel wrote:
Hi All
I have a CSV file that contains dates held in European format (dd/mm/yyyy).
When I open it manually using Excel, the dates remain unchanged. If I open
it using VBA then the dates are changed to US format where they can... so
01/04/2005 becomes 04/01/2005. However dates that cannot be converted eg
23/03/2005 are left as is. I end up with a mixture of dates and formatting
does reset my dates to the correct format!

How can I avoid this problem?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default CSV File - Date Formats

Of course, thanks Rich_z for pointing this out. I can get the source fixed
so that will resolve the problem.

--
Cheers
Nigel



"Rich_z" wrote in
message ...

CSV files have a specification.....! (Yup...)

One of the things it states is that dates should be in the format
YYYYMMDD. It's then up to the receiving application to reformat these
as appropriate.

If you can, get the output changed to conform to the specification,
otherwise rather than input them into a date variable, enter them into
a string and then convert that to a date which will give you control
over the format of the date.


--
Rich_z
------------------------------------------------------------------------
Rich_z's Profile:

http://www.excelforum.com/member.php...o&userid=24737
View this thread: http://www.excelforum.com/showthread...hreadid=394524



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default CSV File - Date Formats

Hi Tom
Yes, a good option but the target application is running in xl97 so the
level of control is limited. I will be getting the source changed to the
specification that Rich_z reminded me of. That is dates as CCYYMMDD. Thanks
for your reply

--
Cheers
Nigel



"Tom Ogilvy" wrote in message
...
I have US English, so I don't personally have to deal with this problem,

but
here is my understanding:


In Excel 2002/2003, there are some options you can use to control this.

expression.Open(FileName, UpdateLinks, ReadOnly, Format, Password,
WriteResPassword, IgnoreReadOnlyRecommended, Origin, Delimiter, Editable,
Notify, Converter, AddToMru, Local, CorruptLoad)

help on Local:
Local Optional Variant. True saves files against the language of

Microsoft
Excel (including control panel settings). False (default) saves files
against the language of Visual Basic for Applications (VBA) (which is
typically US English)


In other versions, you can rename the file as .txt, then open it using the
text import wizard. In the wizards last screen, you can specify for that
column of dates, how they should be interpreted.

--
Regards,
Tom Ogilvy

"Nigel" wrote in message
...
Hi All
I have a CSV file that contains dates held in European format

(dd/mm/yyyy).
When I open it manually using Excel, the dates remain unchanged. If I

open
it using VBA then the dates are changed to US format where they can...

so
01/04/2005 becomes 04/01/2005. However dates that cannot be converted

eg
23/03/2005 are left as is. I end up with a mixture of dates and

formatting
does reset my dates to the correct format!

How can I avoid this problem?

--
Cheers
Nigel








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default CSV File - Date Formats

Hi,

I embedded a hyperlink into a worksheet and used the "hyperlinks.follow"
command in my code eg:

myWorksheet.Cells(RowIndex, lSrc_ci).Hyperlinks(1).Follow

It opens the document as if it has been opened manually (without the date
format problem). Don't know if you can do this without having to embed a
hyperlink in a worksheet...hope this helps

l

"Nigel" wrote:

Hi All
I have a CSV file that contains dates held in European format (dd/mm/yyyy).
When I open it manually using Excel, the dates remain unchanged. If I open
it using VBA then the dates are changed to US format where they can... so
01/04/2005 becomes 04/01/2005. However dates that cannot be converted eg
23/03/2005 are left as is. I end up with a mixture of dates and formatting
does reset my dates to the correct format!

How can I avoid this problem?

--
Cheers
Nigel





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date Formats david d Excel Discussion (Misc queries) 2 September 14th 08 12:29 PM
Help with Date formats ROn Stalenberg[_2_] Excel Discussion (Misc queries) 1 September 10th 08 04:57 AM
DATE FORMATS Lindsay Graham Excel Discussion (Misc queries) 4 August 28th 08 02:17 AM
Date formats mohd21uk via OfficeKB.com New Users to Excel 1 May 16th 06 02:41 PM
Date formats mohd21uk via OfficeKB.com New Users to Excel 3 May 16th 06 01:09 PM


All times are GMT +1. The time now is 08:47 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"