Click here to Skip to main content
12,508,992 members (59,296 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL Server
hi all,
i need to convert date format
2012-11-15 into 15-Nov-2012, we need to convert datetime into datetime not using varchar and char using sql server...,


condition:
need to convert datetime into datetime.


Regards
siva
Posted 31-Jul-12 22:02pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Take date ouput in both ways.
SELECT CONVERT(VARCHAR(9), GETDATE(), 6) StringDate,
       GETDATE()  RegularDate

In gridview column where you are displaying date just change SortExpression to RegularDate & while displaying use StringDate

<asp:BoundField SortExpression="RegularDate" />
    <asp:TemplateField SortExpression="RegularDate"></asp:TemplateField>
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

SELECT CONVERT(VARCHAR(9), GETDATE(), 6)

Try this, hope you found your solution.
  Permalink  
Comments
Member 3962514 1-Aug-12 4:22am
   
SELECT REPLACE(CONVERT(varchar(50), GETDATE(), 106), ' ', '-')

if i use above querry i can get 01-Aug-2012
but i dont want to use char and varchar i need to display its like a datetime
after converting.
pradiprenushe 1-Aug-12 4:27am
   
What is problem with varchar?
Member 3962514 1-Aug-12 4:34am
   
actually my problem is i need to return date format like 01-Aug-2012
in this value should not be varchar or char.
why because of while i am retriving it from the c# win application.
i am bind into the datagridview, so in that grid if we select the column
i mean the date column it should be sorting

case 1:
if i pass its like ur querry its taking as sting(date values)
so it sort my string like below,

01-May-2012
02-Aug-2012
02-May-2012
like that
so if i return the date format it will be work i guess.

or give some suggestion....

Regards
Siva
pradiprenushe 1-Aug-12 4:43am
   
Try my answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160927.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100