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

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?

3

6 Answers

Try like this...

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

For more info :

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>

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like