1

I have a date column where the date format is

2016-07-24

in SQL Server now. Is there any possible way to retrieve the date format as

24-07-2016

through a select statement? and My presently I am using this query

Convert(varchar(10),CONVERT(date,event_enddate,105),126) as "end"

What am I missing here?

Deepak Keynes
  • 2,291
  • 5
  • 27
  • 56

2 Answers2

2
SELECT REPLACE(CONVERT(VARCHAR(10), CAST(event_enddate AS DATE),103), '/', '-') AS [end]

or

SELECT CONVERT(VARCHAR(10), CAST(event_enddate AS DATE), 105) AS [end]

will return your expected format.

More over add square bracket [ ] instead of double quotes " " for your alias name


Sample execution with GETDATE(): Reference

SELECT CONVERT(VARCHAR(10), CAST(GETDATE() AS DATE),105) AS [end]

Output:

04-07-2016
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
1

Were you looking for the below?

SELECT convert(varchar, getdate(), 105)

For other formats, check this.

MusicLovingIndianGirl
  • 5,909
  • 9
  • 34
  • 65