Remove 0 from date result

1

I make this command to bring the date in a YYYY / MM / DD format:

DECLARE @SomeExampleDate DATETIME;
SELECT @SomeExampleDate = '2016/08/20';

SELECT STUFF(REPLACE('/'+CONVERT(CHAR(10),@SomeExampleDate,102), '.', '/'),1,1,'')

But I want that the date that returns to me does not include zeros (0) before the day or month in case of having. I use SQL Server 2014 Express.

    
asked by CarlosOro 20.08.2016 в 21:24
source

1 answer

3

You can use the Format () :

DECLARE @SomeExampleDate DATETIME
SELECT @SomeExampleDate = '2016/08/20'

SELECT FORMAT(@SomeExampleDate, 'yyyy/M/d')
    
answered by 21.08.2016 / 07:41
source