The Original SQL Statement is:
SELECT SA.[RequestStartDate] as 'Service Start Date',
SA.[RequestEndDate] as 'Service End Date',
FROM
(......)SA
WHERE......
The output date format is YYYY/MM/DD, but I want the output date format is DD/MM/YYYY. How can I modify in this statement?
This question is related to
sql
sql-server
tsql
Try:
SELECT convert(nvarchar(10), SA.[RequestStartDate], 103) as 'Service Start Date',
convert(nvarchar(10), SA.[RequestEndDate], 103) as 'Service End Date',
FROM
(......)SA
WHERE......
Or:
SELECT format(SA.[RequestStartDate], 'dd/MM/yyyy') as 'Service Start Date',
format(SA.[RequestEndDate], 'dd/MM/yyyy') as 'Service End Date',
FROM
(......)SA
WHERE......
There's also another way to do this-
select TO_CHAR(SA.[RequestStartDate] , 'DD/MM/YYYY') as RequestStartDate from ... ;
Try like this...
select CONVERT (varchar(10), getdate(), 103) AS [DD/MM/YYYY]
For more info : http://www.sql-server-helper.com/tips/date-formats.aspx
You will want to use a CONVERT() statement.
Try the following;
SELECT CONVERT(VARCHAR(10), SA.[RequestStartDate], 103) as 'Service Start Date', CONVERT(VARCHAR(10), SA.[RequestEndDate], 103) as 'Service End Date', FROM (......) SA WHERE.....
See MSDN Cast and Convert for more information.
Changed to:
SELECT FORMAT(SA.[RequestStartDate],'dd/MM/yyyy') as 'Service Start Date', SA.[RequestEndDate] as 'Service End Date', FROM (......)SA WHERE......
Have no idea which SQL engine you are using, for other SQL engine, CONVERT can be used in SELECT statement to change the format in the form you needed.
Source: Stackoverflow.com