Delimiters
The delimiter character for dates, times or datetime combinations, is the hash (#). See (Quotes (') and Double-Quotes (") - Where and When to use them.) for more on literal delimiters
Formats
The Format() function in VBA can be used with these settings to provide the literal datetime required (NB I'm not aware of any lack of flexibility on the Time Format side so I merely include it to provide usable examples) :
Expand|Select|Wrap|Line Numbers
- Data Type (Example) Format String (Required Result)
- Date (1 February 2003) '\#m\/d\/yyyy\#' (#2/1/2003#)
- Time (6:15:42 PM) '\#hh:n:s\#' (#18:15:42#)
- Date + Time '\#m\/d\/yyyy hh:n:s\#'
- (1 February 2003 6:15:42 PM) (#2/1/2003 18:15:42#)
Like most interpreters of code in their various forms (VBA; SQL; etc), the MS Access Jet SQL interpreter can be clever (MS Access is notoriously forgiving) so will interpret your date literal correctly in many cases even when it is passed in the wrong format. 24 January 2005, for instance, would be worked out correctly in any format I have ever seen used.
Consider the date above though, 1 February 2003. It could be interpreted as 2 January 2003 if passed in British (d/m/yyyy) format or even as 3 February 2001 if passed in yy/m/d format. yyyy/m/d should always be safe though, if not quite standard.
Stick with the standard (m/d/y) if you require your code to be (more) portable though.
Gotcha
Related to the previous paragraph.
One thing it is very important to understand is that dates that are specified using a format other than the SQL standard (EG. A date of 13th February 2015 specified as #13/2/2015#.) will still be interpreted as a valid date if they can nevertheless be recognised. This can be a very hard situation to discover when testing and debugging code so be careful. It generally means the format used is incorrect but you weren't lucky enough to discover it during testing because it was between 13th and the end of the month.
NB.
Except in countries where the SQL format matches the local format, this will mean that a string will be interpreted one way when used in VBA, yet in another way when interpreted by SQL.
Regional Settings
Another, rather nasty, problem raises its head when dealing with Regional Settings in regions where the standard date format character (Slash (/) for many countries including USA & UK as well as various others in Europe) is replaced by any other character. Countries such as Denmark for instance, where their dates are in the format (d-m-y). This issue is really a problem with VBA and the Format() command specifically. A standard format string of "m/d/yyyy", when used by Format() is parsed and interpreted in light of the Regional Settings such that it is treated as if it were "m-d-yyyy" instead. This is clearly not good news when trying to produce a conformant string for a SQL command string. The way to get around this, and be fully portable internationally, is to use a backslash (\) before each slash (/) in the format string - as illustrated in the Formats section above. This ensures that the backslashes are not recognised as format characters, yet still end up in the same place in the returned string value.
Date Variables
Date variables do not need to be formatted when passed to SQL as a reference (as opposed to a literal string of characters within the SQL).
DateTime fields in a record, dates entered into parameters in a parameter query or any function returning a DateTime result will be correctly interpreted by the SQL engine IF IT IS INTERPRETED BY SQL and not pre-processed by Access into a date literal. In the latter case the format should be done in the standard fashion.
Debugging
It's easy to get some of this stuff wrong so I always recommend doing a 'Debug.Print strSQL' before passing the string to the SQL engine when developing the code, or even where you know there is a problem with it somewhere. Use Ctrl-G from the VBA window to show and go to the Immediate Pane where the string is displayed.
Expand|Select|Wrap|Line Numbers
- Debug.Print strSQL
- DoCmd.RunSQL strSQL
Allen Browne has some further help on this topic (International Dates in Access).