ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How does VBA interpret Dates? (https://www.excelbanter.com/excel-programming/392986-how-does-vba-interpret-dates.html)

Greg Glynn

How does VBA interpret Dates?
 
Living and working in Australia, our conventional way to represent
dates is dd/mm/yy. I think our American cousins us mm/dd/yy as their
default.

Is VBA, I get this:

MyDate = #13/12/2007#
? Month(mydate)
12
In this instance, VBA interprets the 2nd qualifier as the month (12),
possibly because 13 cannot be a month.


MyDate = #11/12/2007#
? Month(mydate)
11
In this instance, VBA interprets the 1st qualifier as the month.

This is causing me grief because I have an application that reads text
files and tries to interpret US style dates. Can anyone give me
guidance on the best way to interpret dates?

Thanks in advance.


Greg


Dave Peterson

How does VBA interpret Dates?
 
Why not just parse the text string into 3 pieces--then recombine it the way you
want:

mydate = dateserial(yearportion, monthportion, dayportion)

Maybe you could use a bunch of left's, right's or mid's to extract each piece.



Greg Glynn wrote:

Living and working in Australia, our conventional way to represent
dates is dd/mm/yy. I think our American cousins us mm/dd/yy as their
default.

Is VBA, I get this:

MyDate = #13/12/2007#
? Month(mydate)
12
In this instance, VBA interprets the 2nd qualifier as the month (12),
possibly because 13 cannot be a month.

MyDate = #11/12/2007#
? Month(mydate)
11
In this instance, VBA interprets the 1st qualifier as the month.

This is causing me grief because I have an application that reads text
files and tries to interpret US style dates. Can anyone give me
guidance on the best way to interpret dates?

Thanks in advance.

Greg


--

Dave Peterson

Tom Ogilvy

How does VBA interpret Dates?
 
Just to add to Dave's advice, in VBA if you have a date string/text, it will
be interpreted as a US format if possible (mm/dd/yy).

--
Regards,
Tom Ogilvy


"Greg Glynn" wrote:

Living and working in Australia, our conventional way to represent
dates is dd/mm/yy. I think our American cousins us mm/dd/yy as their
default.

Is VBA, I get this:

MyDate = #13/12/2007#
? Month(mydate)
12
In this instance, VBA interprets the 2nd qualifier as the month (12),
possibly because 13 cannot be a month.


MyDate = #11/12/2007#
? Month(mydate)
11
In this instance, VBA interprets the 1st qualifier as the month.

This is causing me grief because I have an application that reads text
files and tries to interpret US style dates. Can anyone give me
guidance on the best way to interpret dates?

Thanks in advance.


Greg




All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com