Query - format MS SQL date/time extened that is linked to Access as yyyy-mm-dd (1 Viewer)

thefirstbigk

New member
Local time
Today, 08:10
Joined
Mar 27, 2023
Messages
2
Greetings -


I'm trying to create a select query in Access that will report a MS SQL Date/Time Extended field formatted as yyyy-mm-dd.


For example:


from a linked MS SQL table - one example record is: 10/31/2022 8:00:15 AM


I would like my query result to be : 2022/10/31


I've tried several Format methods in Access and the result is always: #error


I'm using a local desktop MS SQL Server 2019 and Microsoft® Access® for Microsoft 365 MSO (Version 2302 Build 16.0.16130.20332) 64-bit if that makes any difference.


Any help or advice would be much appreciated.


BigK
 

Minty

AWF VIP
Local time
Today, 13:10
Joined
Jul 26, 2013
Messages
10,371
Which ODBC Driver are you using - the older ones don't handle the DateTime2 format very well, it is often seen as text.
In all honesty, even the newer driver and latest access versions don't play nicely with it.

If you have the option change it back to a basic DateTime data type.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:10
Joined
May 7, 2009
Messages
19,245
on MSSMS, create a View from your table:

SELECT ID, CONVERT(varchar, DateTimeFieldHere, 101) AS Expr1, Name
FROM dbo.test_table

save your view.

now, on MSA, link the view.

use the Linked view in your query:

Code:
SELECT dbo_View_1.ID, Format([Expr1],"yyyy/mm/dd") AS Dte
FROM dbo_View_1;

you can even create a function to convert it first to real view:
Code:
Public Function fnToDate(ByVal var As Variant) As Date
fnToDate = var
End Function


your SQL query:
Code:
SELECT dbo_View_1.ID, fnToDate([Expr1]) AS Dte, dbo_View_1.[name]
FROM dbo_View_1;
 

Users who are viewing this thread

Top Bottom