Format SQL Server date/time output with CONVERT()

Use SQL Server CONVERT() when a query specifically needs a textual date/time representation. Keep the underlying column typed as date, datetime2 or another date/time type; formatting is a presentation step.

Time only

rs.Open "SELECT CONVERT(char(8), issue_dt, 108) AS formatted_time FROM dbo.dt", conn

Style 108 produces a 24-hour hh:mm:ss representation.

22:02:00

Using a shorter char length truncates the displayed text, but an explicit target length matching the intended format is clearer.

Date only in U.S. display format

rs.Open "SELECT CONVERT(char(10), issue_dt, 101) AS formatted_date FROM dbo.dt", conn
12/22/2007

Style 101 uses mm/dd/yyyy. For machine-readable interchange, prefer an ISO style such as 23 (yyyy-mm-dd) or 126.

Common CONVERT() date/time styles

StyleNameTypical output
0 or 100Default datetimemon dd yyyy hh:miAM
101U.S.mm/dd/yyyy
102ANSIyyyy.mm.dd
103British/Frenchdd/mm/yyyy
104Germandd.mm.yyyy
105Italiandd-mm-yyyy
106Day mon yeardd mon yyyy
107Mon day, yearMon dd, yyyy
108Timehh:mi:ss
109Default + millisecondsmon dd yyyy hh:mi:ss:mmmAM
110USAmm-dd-yyyy
111Japanyyyy/mm/dd
112ISO compactyyyymmdd
113Europe + millisecondsdd mon yyyy hh:mi:ss:mmm
114Time + millisecondshh:mi:ss:mmm
120ODBC canonicalyyyy-mm-dd hh:mi:ss
121ODBC canonical + millisecondsyyyy-mm-dd hh:mi:ss.mmm
23ISO dateyyyy-mm-dd
126ISO 8601yyyy-mm-ddThh:mi:ss.mmm
127ISO 8601 with Zyyyy-MM-ddThh:mm:ss.fffZ
130Hijridd mon yyyy hh:mi:ss:mmmAM
131Hijridd/mm/yyyy hh:mi:ss:mmmAM
Styles that use two-digit years can be ambiguous and some style conversions are nondeterministic. Prefer four-digit-year and ISO representations when the value will be parsed again rather than merely displayed.

ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer