Apologies - I was typing code from memory, always a bad idea!
Here's the function I actually use (it has a couple of other bells and whistles):-
Public Function FormatDate(datInput As Date, Optional intOffset As Integer, Optional strFormat As String) As String
' Formats the date based on passed parameters
' Default option will format it in US format for use in Jet SQL
If strFormat = "" Then strFormat = "\#mm\/dd\/yyyy\#"
FormatDate = VBA.Format(datInput + intOffset, strFormat)
End Function
What I forgot was the \ backslashes to escape the characters in the format string.
To answer your other question, Access/JET is the only database I know that uses this syntax, but most RDBMSs are fussy about literal date formats. DB2 is a particular pain, timestamp (= date and time together) fields have to have the time specified down to microseconds, e.g. '2007-05-31-17:06:34.123456' - not easy!
Good luck with your coding...
Richard
|