Wednesday, December 13, 2017

SQL SERVER - How convert date/datetime to string

You can use convert() function with last parameter which tells how to convert.
select convert( varchar(10), getdate() ) union
select convert( varchar(10), getdate(), 101 ) union
select convert( varchar(10), getdate(), 102 ) union
select convert( nvarchar(10), getdate(), 103 ) union
select convert( varchar(10), getdate(), 104 ) union
select convert( nvarchar(10), getdate(), 105 ) 
Output:
----------
12/13/2017
13.12.2017
13/12/2017
13-12-2017
2017.12.13
Dec 13 201

(6 row(s) affected)

No comments:

Post a Comment