You can use the CONVERT function to cast a datetime datatype to a formatted string.
You can also use some built-in codes to convert into a specific format. Here are the options built into SQL Server.
SQL Code:
SELECT GETDATE() AS [Result] --2021-05-29 18:50:18.737
DECLARE @convert_code INT = 100
SELECT CONVERT(VARCHAR(30), GETDATE(), @convert_code) AS [Result]
Output:
|
@convert_code |
Result |
|
100 |
May 29 2021 6:50PM |
|
101 |
05/29/2021 |
|
102 |
2021.05.29 |
|
103 |
29/05/2021 |
|
104 |
29.05.2021 |
|
105 |
29-05-2021 |
|
106 |
29 May 2021 |
|
107 |
May 29, 2021 |
|
108 |
18:50:18 |
|
109 |
May 29 2021 6:50:18:737PM |
|
110 |
05-29-2021 |
|
111 |
2021/05/29 |
|
112 |
20210529 |
|
113 |
29 May 2021 18:50:18:737 |
|
114 |
18:50:18:737 |
|
120 |
2021-05-29 18:50:18 |
|
121 |
2021-05-29 18:50:18.737 |
|
126 |
2021-05-29T18:50:18.737 |
|
127 |
2021-05-29T18:50:18.737 |
|
130 |
18 ???? 1442 6:50:18:737PM |
|
131 |
18/10/1442 6:50:18:737PM |
No comments:
Post a Comment