Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I used the CONVERT(data_type(length), expression, style) function for modifying the date format in a SELECT query.

Declare @dt nvarchar(20)

Select @dt = Convert(nvarchar(20), SalesDate, 113) FROM SalesTable

The format I need is 'DD-MMM-YYYY' (eg. '05-Jul-2013') though I could not find the proper style number (eg. 113) for this particular format. 

Can anyone help me with this?

1 Answer

0 votes
by (12.7k points)
edited by

You can try the following code:

Declare @dt NVARCHAR(20)

Select
    @dt = REPLACE(CONVERT(CHAR(15), SalesDate, 106),' ',' - ')
FROM SalesTable

Kick-start your career in SQL with the perfect SQL online course by Intellipaat now!

Related questions

0 votes
1 answer
asked Dec 4, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...