how to convert datetime format [Resolved]

Posted by Ankitsrist under ASP.NET on 1/2/2013 | Points: 10 | Views : 1004 | Status : [Member] | Replies : 3
hello
i have a gridview nd one column shows start date(startdate is the column name fetching from DB ) so m trying to convert its format in this way
"SELECT [monthlytrid],[state],[projectname],[length],[minimum_length],convert(varchar(50),startdate,101) ,[enddate] FROM [test].[dbo].[monthlytarget]";
nd it converts also but column name change into Column1 in place of startdate...why it is happng




Responses

Posted by: Chaithragm on: 1/2/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
in gridview ..use formatstring {0:dd-mm-yyyy}

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandeepmhatre on: 1/2/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
"SELECT [monthlytrid],[state],[projectname],[length],[minimum_length],convert(varchar(50),startdate,101) as StartDate ,[enddate] FROM [test].[dbo].[monthlytarget]";


when you convert format a column you need to set alias name to that column , other wise SQL will provide by default name as Column 1 or column with title (no column Name)
try this example

SELECT getdate(), getdate()

you will get output like this

(No column name) (No column name)
2013-01-02 16:23:41.700 2013-01-02 16:23:41.700

Sandeep M,
Software Developer
Follow me on :
http://sandeepmhatre.blogspot.in

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 1/2/2013 [Member] Starter | Points: 25

Up
0
Down
thank u sir now its working correctly.....:)

Ankitsrist, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response