How do I get this date format in Sql Server 2014?

2

I am having problems when formatting a date in SQLSERVER, my query is

SELECT CONVERT(VARCHAR(10), FECHA_INI_FALLA, 13) AS FechaFalla

and the result I get is

12 SEP 2017

and what I want to get is

12/SEP/2017 O 12-SEP-2017

It should be noted that I do not want to show the time, minutes and seconds

What should I change to get that format?

    
asked by Luis Fernando 12.09.2017 в 18:48
source

4 answers

4

From SQL Server 2000 :

SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 13), ' ', '/')

Starting with SQL Server 2012 :

SELECT FORMAT( GETDATE(), 'dd/MMM/yyyy', 'en-US' )

You'll get:

  

12 / Sep / 2017

DEMO

For your case:

SELECT FORMAT(FECHA_INI_FALLA, 'dd/MMM/yyyy', 'en-US' )

Reference:

answered by 12.09.2017 / 19:01
source
3

Use:

Modification according to the edition of the OP question about not showing time on the date:

SELECT replace(CONVERT(nvarchar,  Convert(Date, FECHA_INI_FALLA), 13), ' ', '/')

or

SELECT replace(CONVERT(nvarchar,  Convert(Date, FECHA_INI_FALLA), 13), ' ', '-')
  

Thanks to Davilo for the suggestion of limitation of information using   varchar which does not perform a double cast:

SELECT replace(CONVERT(VARCHAR(11), GETDATE(), 13), ' ', '/')
SELECT replace(CONVERT(VARCHAR(11), GETDATE(), 13), ' ', '-')

Greetings

    
answered by 12.09.2017 в 18:54
0

Use Convert , with format 106, that already omits information of hours, minutes, etc.

Then, replace the spaces with '-' or '/' , as you prefer:

select replace(convert(varchar, FECHA_INI_FALLA, 106), ' ', '-')

It will give you the desired result.

    
answered by 12.09.2017 в 19:16
-1

You should use:

SELECT CONVERT(VARCHAR(10), FECHA_INI_FALLA, 103) AS FechaFalla

Since the 103 parameter is the British / French format: dd / mm / yyyy

For more details, see: link

Greetings!

    
answered by 12.09.2017 в 19:03