Vin05
Vin05

Reputation: 587

How to Convert Datetime to Date in dd/MM/yyyy format

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

So i wrote query like

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

But when i write order by Tran_Date, it is giving me the result in wrong order.

Can some body please suggest what should i do.

Thanks

Upvotes: 11

Views: 130305

Answers (2)

Madhivanan
Madhivanan

Reputation: 13700

Give a different alias

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

Upvotes: 19

Habib
Habib

Reputation: 223277

You need to use convert in order by as well:

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

Upvotes: 4

Related Questions