Using Excel 2010, the user selects a date in a cell. Code converts the date to a string to use in the query. This is the string format: "CONVERT(DATETIME, '2013-06-30 00:00:00', 102) ". If the user has a language setting other than English the query doesn't work because the date doesn't convert to the string in the format shown. Having the user change language settings is not an option so how can I get the date into a format that will work in the query?
Public Sub GetDates()
Worksheets("Select Date Range").Select
dStartDate = Selection.Value
dEndDate = Selection.Value
' convert date to format needed for queries
' CONVERT(DATETIME, '2013-06-30 11:59:59', 102)
cStartDate = "CONVERT(DATETIME, '" & dStartDate & " 00:00:00', 102)"
cEndDate = "CONVERT(DATETIME, '" & dEndDate & " 00:00:00', 102)"