selva kumar

selva kumar

  • NA
  • 557
  • 189k

how to sort the date ?

May 17 2013 2:03 AM
here is my sample code

create table [sample](T_id int identity(1,1),date varchar(50));

04-05-2013
07-03-2013
10-01-2013
20-08-2013
18-02-2013
09-07-2013
07-06-2013
05-12-2013
05-12-2013
05-12-2013

i want to sort the date based on DD-MM-YYYY fomat:

i m using below query

select distinct convert(varchar,date,103),convert(datetime,date,103)as date from [sample] order by date desc;

i m getting below output,

[no column name]       date
05-12-2013         2013-12-05 00:00:00.000
20-08-2013         2013-08-20 00:00:00.000
09-07-2013         2013-07-09 00:00:00.000
07-06-2013         2013-06-07 00:00:00.000
04-05-2013         2013-05-04 00:00:00.000
07-03-2013         2013-03-07 00:00:00.000
18-02-2013         2013-02-18 00:00:00.000
10-01-2013         2013-01-10 00:00:00.000

how do i get the column name for fist one...? can anyone help my question..


Answers (9)