I always use dates/times as dd/mmm/yyyy hh:mm:ss
In VBA, I export sheets to CSV. It looks as if some of my dates are getting garbled (days & months swapped). Again, I see this in the exported CSV when I look at it via e.g. Notepad.... I haven't been able to get to the root-cause but was wondering (A) if this is known [which prevents me from re-inventing wheels] and (B) what can be done to avoid this..??
Thanks!
Date mess-up on CSV output in VBA?
-
- BronzeLounger
- Posts: 1253
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Date mess-up on CSV output in VBA?
Last edited by HansV on 06 Apr 2010, 16:50, edited 1 time in total.
Reason: to correct typo in subject
Reason: to correct typo in subject
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Date mess-up on CSV outpout in VBA?
In Excel the dd/mmm/yyyy is a format that is assigned to dates. You see it in this format in Excel, but it does not mean that the PC sees it in this format. Your regional setting may be yyyy-mm-dd, and if this is the case, the export may send it to the text file based on the original date format, and not the format of the cells in Excel.
Either change the date format on your system, or you will need to construct a format in VBA to remodel the date as it sends it to the text file.
Either change the date format on your system, or you will need to construct a format in VBA to remodel the date as it sends it to the text file.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78523
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Date mess-up on CSV outpout in VBA?
VBA inherently uses US English formats: the point is used as decimal separator, and the date format is m/d/yyyy.
If you format the dates as dd-mmm-yyyy, they should be OK, but if you use dd/mm/yyyy or similar, confusion arises.
You could also use formulas of the form =TEXT(A1,"dd-mmm-yyyy")
The real solution is obviously to become an American.
If you format the dates as dd-mmm-yyyy, they should be OK, but if you use dd/mm/yyyy or similar, confusion arises.
You could also use formulas of the form =TEXT(A1,"dd-mmm-yyyy")
The real solution is obviously to become an American.
Best wishes,
Hans
Hans
-
- BronzeLounger
- Posts: 1253
- Joined: 03 Feb 2010, 19:59
- Location: Terneuzen, the Netherlands
Re: Date mess-up on CSV outpout in VBA?
Somehow my "Quick reply" got lost twice...
My setting in Windows is identical to that used in Excel.
Could I convert to text by adding a leading single quote and write out the month like: '06-Apr-2010 ??
Could I assume that upon CSV IMPORT and Excel would convert to a proper date matching that of the local settings in Excel and the OS?
My setting in Windows is identical to that used in Excel.
Could I convert to text by adding a leading single quote and write out the month like: '06-Apr-2010 ??
Could I assume that upon CSV IMPORT and Excel would convert to a proper date matching that of the local settings in Excel and the OS?
-
- Administrator
- Posts: 78523
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Date mess-up on CSV outpout in VBA?
Inserting an apostrophe before the date converts it to text. It should export OK, but the apostrophe won't be saved with the .csv file, so next time you open the .csv file in Excel, the apostrophe will be lost.
It's all very tricky. If I have to work with CSV files, I usually set my Windows locale to US temporarily.
It's all very tricky. If I have to work with CSV files, I usually set my Windows locale to US temporarily.
Best wishes,
Hans
Hans
-
- Administrator
- Posts: 78523
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Date mess-up on CSV outpout in VBA?
BTW, if you're composing a Quick Reply, you must click Submit, not POSTREPLY - the latter button will destroy your quick reply.
Best wishes,
Hans
Hans