How to convert date and time in dd / MM / yyyy format

I want to write a query to get the date in dd / MM / yyyy format. (I do not want time).

So, I wrote a query like

SELECT Convert(varchar,A.InsertDate,103) as Tran_Date 

But when I write the order by Tran_Date, it gives me the result in the wrong order.

Can any body suggest what I should do.

thanks

+6
source share
2 answers

Give another alias

 SELECT Convert(varchar,A.InsertDate,103) as converted_Tran_Date from table as A order by A.InsertDate 
+12
source

You should also use the conversion in order:

 SELECT Convert(varchar,A.InsertDate,103) as Tran_Date order by Convert(varchar,A.InsertDate,103) 
+2
source

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


All Articles