Change Date Format (DD / MM / YYYY) in SQL SELECT Statement

Original SQL statement:

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 the output date format is DD / MM / YYYY. How can I change this statement?

+7
source share
5 answers

Try it...

select CONVERT (varchar(10), getdate(), 103) AS [DD/MM/YYYY]

For more information: http://www.sql-server-helper.com/tips/date-formats.aspx

+14
source

Changed to:

SELECT FORMAT(SA.[RequestStartDate],'dd/MM/yyyy') as 'Service Start Date', SA.[RequestEndDate] as 'Service End Date', FROM (......)SA WHERE......

You can’t imagine which SQL engine you are using, for another SQL engine in the SELECT statement you can use CONVERT to change the format in the form you need.

+4
source

CONVERT().

:

SELECT CONVERT(VARCHAR(10), SA.[RequestStartDate], 103) as 'Service Start Date', CONVERT(VARCHAR(10), SA.[RequestEndDate], 103) as 'Service End Date', FROM (......) SA WHERE.....

. MSDN Cast and Convert.

+1

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......

:

SELECT format(SA.[RequestStartDate], 'dd/MM/yyyy') as 'Service Start Date', 
       format(SA.[RequestEndDate], 'dd/MM/yyyy') as 'Service End Date', 
FROM
(......)SA
WHERE......
0

this-

select TO_CHAR(SA.[RequestStartDate] , 'DD/MM/YYYY') as RequestStartDate from ... ;
0
source

Source: https://habr.com/ru/post/1648743/


All Articles