Click here to Skip to main content
Rate this: bad
good
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 23: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 at 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 at 1-Aug-12 4:27am
   
What is problem with varchar?
Member 3962514 at 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 at 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
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 1 Aug 2012
Copyright © CodeProject, 1999-2014
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