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?
36 Answers
Try like this...
select CONVERT (varchar(10), getdate(), 103) AS [DD/MM/YYYY] 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.
There's also another way to do this-
select TO_CHAR(SA.[RequestStartDate] , 'DD/MM/YYYY') as RequestStartDate from ... ; 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.
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...... I was using oracle and I had to select multiple columns and output the date column in YYYY-MM-DD format, and this worked select <column_1>, to_char(<date_column>, 'YYYY-MM-DD') as <Alias_name> from <table_name>