Bernard Nongpoh
Bernard Nongpoh

Reputation: 1058

SQL query to convert date format to another

How to convert from 02/03/2012 to 2/3/2012 format in SQL Server

Upvotes: 1

Views: 3189

Answers (4)

user1583384
user1583384

Reputation: 230

This is going to get your exact results..

Declare @test datetime 

Set @test = '02/03/2012'

Print  Convert(VARCHAR(10) , @test,101 )

Print  REPLACE(LEFT(Convert(VARCHAR(10) , @test,101 ),5),0,'') + RIGHT(Convert(VARCHAR(10) , @test,101),5)

RESULT:

02/03/2012
2/3/2012

Upvotes: 0

A.Goutam
A.Goutam

Reputation: 3494

And for your question answer

SELECT Convert(varchar, GETDATE(),1)  

Upvotes: 1

shrisha
shrisha

Reputation: 445

if you're running SQL Server 2012, you can do this:

SELECT FORMAT ( @your_date_value, 'd', 'en-US' )

See http://msdn.microsoft.com/en-us/library/hh213505.aspx

Upvotes: 1

Related Questions