Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 434
Fabre Avatar asked Jul 22 '16 08:07

Fabre


People also ask

How do I change the date format in a database?

We change the date format from one format to another. For example - we have stored date in MM-DD-YYYY format in a variable, and we want to change it to DD-MM-YYYY format. We can achieve this conversion by using strtotime() and date() function.


2 Answers

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.

like image 187
PSo Avatar answered Sep 22 '22 14:09

PSo


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

like image 27
AmanKumar Avatar answered Sep 21 '22 14:09

AmanKumar