This can't be right...
As SkipVought would have said, a date is a date is a number...
meaning, a date is stored as a number when dumped to a date/time field, and when assigned to a variable of datatype date.
If you input the date May 10, 2005 into a table through for instance:
[tt]"update mytable set mydate = #2005-05-10#"[/tt]
Then the following should occur on three different locale after opening a recordset on the same table:
[tt]debug.print rs.fields("mydate").value, date
10.05.2005 23.06.2005 ' Norwegian
10/05/2005 23/06/2005 ' UK
5/10/2005 6/23/2005 ' US[/tt]
But - this is only the
displayed date! What's "stored" in the field, and available through the date function are numbers - so - comparing
real dates in code, regardless of whether they are variables of datatype date, or fields of datatype date/time will (at least far as I've found out) perform correct regardless of locale, because it compares numbers!!!
They are only viewed as a date whenever it's displayed. VB(A) works with the number.
Try (in immediate pane - ctrl+g):
[tt]? format$(date,"0")
? format$(38526, "yyyy-mm-dd")[/tt]
My suspicion with some of the above, is that there's some formatting going on, where real dates are converted to strings, reassigned either to date variables, variants or dates - but in the process implicitly "recreated/coerced/toggled" between US/UK dates. Remember that when using the format functtion, you are effectively formatting a date to a string, and if trying to assign a string to a variable of datatype date, an implicit conversion will be performed - the success of this may be what you're experiencing, cause this is a culprit for many until they get sufficient grasp on working with dates...
Either that, or you're assigning the date to a date variable using the wrong method. In VBA, when using litterals, they must be in US format, i e:
[tt]dim dtMyDate as date
dtMyDate = #1/5/2005# ' assigns 5. Jan 2005 regardless of locale
dtMyDate = #15/5/2005# ' assigns 15. May 2005 because
' 15 is higher than 12 (max month), so the date
' is coerced[/tt]
Which of course leads up to the following fun test, at least when you're not on US locale:
[tt]dtMyDate = #1/5/2005#
msgbox dtMyDate[/tt]
A nice trick, is using the DateSerial function, to make it completely clear what one is assigning
[tt]dtMyDate = dateserial(2005, 5, 1)[/tt]
The only time one would really need to format dates, is when performing dynamic SQL (as in my update sample), where, when concatenating the date into a string which is passed to the Jet engine for evaluation and execution, an unambiguous format is needed...
Also keep in mind that the "mm/dd/yyyy" format is far from safe, if formatting is needed, use "mm\/dd\/yyyy" or "yyyy-mm-dd", see
International Dates in Access for more info.
Roy-Vidar